Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggsurvplot(): Plotting multiple surv objects on the same graph #195

Closed
kassambara opened this issue Apr 16, 2017 · 7 comments
Closed

ggsurvplot(): Plotting multiple surv objects on the same graph #195

kassambara opened this issue Apr 16, 2017 · 7 comments

Comments

@kassambara
Copy link
Owner

(User request by-email)

In oncology, we wish to plot time on treatment, progression free survival and overall survival on the same graph (and often also stratified by treatment assignment).

A simple solution to add multiple surv object on the same graph wanted.

The R code to generate this type of plot would look like this:

ggsurvplot(c(PFS.fit, OS.fit), ...)

The plot would look like this:

image002

@kassambara
Copy link
Owner Author

New option combine = TRUE is now available in the ggsurvplot() function to combine a list survfit objects on the same plot. Alias of the ggsurvplot_combine() function.

Load required packages

library("survival")
library("survminer")

Create a demo data set

set.seed(123)
d.demo <- data.frame(
  os.time = colon$time, 
  os.status = colon$status,
  pfs.time = sample(colon$time),
  pfs.status = colon$status,
  sex = colon$sex, rx = colon$rx, adhere = colon$adhere
)

Ex1: Combine null models

  • Compute two survival curves (PFS and OS), null models
pfs <- survfit( Surv(pfs.time, pfs.status) ~ 1, data = d.demo)
os <- survfit( Surv(os.time, os.status) ~ 1, data = d.demo)
  • Combine the two survival curves on one graph:
fit <- list(PFS = pfs, OS = os)
ggsurvplot(fit, data = d.demo, combine = TRUE, # Combine curves
           risk.table = TRUE,                  # Add risk table
           conf.int = TRUE,                    # Add confidence interval
           conf.int.style = "step",            # CI style, use "step" or "ribbon"
           censor = FALSE,                     # Remove censor points
           tables.theme = theme_cleantable(),  # Clean risk table
           palette = "jco")

rplot

Ex2: Combine stratified curves

  • Compute survival curves of patients stratified by treatment assignments (rx)
pfs <- survfit( Surv(pfs.time, pfs.status) ~ rx, data = d.demo)
os <- survfit( Surv(os.time, os.status) ~ rx, data = d.demo)
  • Combine the two survival curves:
fit <- list(PFS = pfs, OS = os)
ggsurvplot(fit, data = d.demo, combine = TRUE,     # Combine curves
          risk.table = TRUE, tables.height = 0.35, # Adjust tables height
          tables.theme = theme_cleantable(),       # Clean risk table
          censor = FALSE,                          # Remove censor points
          palette = "jco"
          )

rplot08

@klausmiller
Copy link

Does this also work with ggflexsurvplot?

@fthielen
Copy link

I would like to do the same but with data from different sources. So my data = d.demo would actually need to be specified for two different data sources. (How) is this possible?

@nmolanog
Copy link

I would like to do the same but with data from different sources. So my data = d.demo would actually need to be specified for two different data sources. (How) is this possible?

I am in the same situation also. I just had to create a merged data.frame from the different sources to achieve a work around

@smruti272mokal
Copy link

Thanks for the post! It was really helpful but can we show the median survival time with the use of surv.median.line which is available in ggsurvplot when we combine the graphs? I tried it but couldn't get the median survival line. Please suggest me an option for the same .

Thank you

@dimpapa85
Copy link

I want to do the same but combine an exponential survival curve with a Weibull in the same graph. Any idea how to do it?

@TinkaJ
Copy link

TinkaJ commented Mar 3, 2022

I am trying to combine 3 null models in one graph, but it doesn't work.

Ex1: Combine 3 null models
Compute two survival curves (PFS and OS), null models
pfs <- survfit( Surv(pfs.time, pfs.status) ~ 1, data = d.demo)
os <- survfit( Surv(os.time, os.status) ~ 1, data = d.demo)
third <- survfit( Surv(thi.time, thi.status) ~ 1, data = d.demo)

Combine three survival curves on one graph:
fit <- list(PFS = pfs, OS = os) of fit <- list(pfd, os, third) <- it seems there are only 2 arguments here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
  翻译: