aposo.wie
aposo.wie

Reputation: 1

Merge Two Kaplan Meier Curve with ggsurvplot

I have two different data set, which basically contains the same data, but one is for baseline age 19 or younger (data.all.agefs.under19) and the other one is for older than 19 (data.all.agefs.above19)

The survival object of each is defined as:

surv.all.agefs.under19 <- Surv(time = data.all.agefs.under19$follow.up.years, event = data.all.agefs.under19$death.specific)
surv.all.agefs.above19 <- Surv(time = data.all.agefs.above19$follow.up.years, event = data.all.agefs.above19$death.specific)

The Cox PH model is defined as:

cox.all.agefs.under19 <- coxph(surv.all.agefs.under19 ~ factor1 + factor2 + factor3, data = data.all.agefs.under19)
cox.all.agefs.above19 <- coxph(surv.all.agefs.above19 ~ factor1 + factor2 + factor3, data = data.all.agefs.above19)

I would like to create a plot with Kaplan Meier curves for both, but so far, I can only create one for each one using ggsurvplot:

ggsurv <- ggsurvplot(survfit(cox.all.agefs.under19), data = data.all.agefs.under19, palette = "#2E9FDF", ggtheme = theme_minimal(), legend = "none")
ggsurv <- ggsurvplot(survfit(cox.all.agefs.above19), data = data.all.agefs.above19, palette = "#2E9FDF", ggtheme = theme_minimal(), legend = "none")

So how do I merge the two curves into the same plot?

Upvotes: 0

Views: 3903

Answers (2)

garcesj
garcesj

Reputation: 589

There's another possible way, also within survminer package:

colnames(data.all.agefs.under19) <- paste0(colnames(data.all.agefs.under19), "_u19")
colnames(data.all.agefs.above19) <- paste0(colnames(data.all.agefs.above19), "_a19")

data.all.agefs <- cbind(data.all.agefs.under19, data.all.agefs.above19)

ggsurvplot_combine(list(under19 = survfit(Surv(follow.up.years_u19, death.specific_u19) ~ factor1_u19 + factor2_u19 + factor3_u19, data = data.all.agefs), 
                        above19 = survfit(Surv(follow.up.years_a19, death.specific_a19) ~ factor1_a19 + factor2_a19 + factor3_a19, data = data.all.agefs)), 
                   data = data.all.agefs)

Upvotes: 1

YBS
YBS

Reputation: 21297

You can append the data into one long data frame and define a variable agegrp to distinguish the two age groups. Then you can plot as shown below.

df1 <- lung
df1$agegrp <- df1$sex

fitme <- survfit(Surv(time, status) ~ agegrp, data = df1) 

  ggsurv2 <- plot(fitme ,  
                  xlim = c(0,1200),
                  main = "Survival curves based on Kaplan-Meier estimates",
                  xlab = "Time in days",      # customize   X axis label.
                  ylab = "Overall survival probability"  # Y axis label
  )
  temp <- lines(fitme, lwd=2:1, col = c("red", "blue"))
  text(temp, c("Under19", "Above19"), adj= -.1) # labels just past the ends
  

output

Update:

Use ggsurvplot as shown below

ggsurv <- ggsurvplot(
    fitme,                   # survfit object with calculated statistics.
    data = df1,              # data used to fit survival curves.
    risk.table = TRUE,       # show risk table.
    pval = TRUE,             # show p-value of log-rank test.
    conf.int = TRUE,         # show confidence intervals for
    # point estimates of survival curves.
    palette = c("#E7B800", "#2E9FDF"),
    xlim = c(0,1200),         # present narrower X axis, but not affect
    # survival estimates.
    xlab = "Time in days",    # customize X axis label.
    break.time.by = 100,      # break X axis in time intervals by 500.
    ggtheme = theme_light(),  # customize plot and risk table with a theme.
    risk.table.y.text.col = T,# colour risk table text annotations.
    risk.table.height = 0.25, # the height of the risk table
    risk.table.y.text = FALSE,# show bars instead of names in text annotations
    # in legend of risk table.
    ncensor.plot = TRUE,      # plot the number of censored subjects at time t
    ncensor.plot.height = 0.25,
    conf.int.style = "step",  # customize style of confidence intervals
    surv.median.line = "hv",  # add the median survival pointer.
    legend.labs = c("Under19", "Above19")  # change legend labels.
  )

output2:

Upvotes: 2

Related Questions