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 · 5 comments

Comments

Projects
None yet
5 participants
@kassambara
Copy link
Owner

kassambara commented Apr 16, 2017

(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

This comment has been minimized.

Copy link
Owner Author

kassambara commented Apr 28, 2017

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

kassambara added a commit that referenced this issue Apr 28, 2017

kassambara added a commit that referenced this issue Apr 28, 2017

@kassambara kassambara closed this Apr 28, 2017

@klausmiller

This comment has been minimized.

Copy link

klausmiller commented Apr 26, 2018

Does this also work with ggflexsurvplot?

@fthielen

This comment has been minimized.

Copy link

fthielen commented Jan 18, 2019

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

This comment has been minimized.

Copy link

nmolanog commented Feb 28, 2019

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

This comment has been minimized.

Copy link

smruti272mokal commented Mar 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.