Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Survminer – arrange multiple ggsurvplot and ggadjustedcurves

I would like to combine survminer plots (like an arrange_ggsurvplots() ): ggsurvplot (for Kaplan Meier model) and ggadjustedcurves (for Cox).

library(survminer)
fitKM  <- survfit(Surv(time, status) ~ sex, data = lung)
fitCox <- coxph(Surv(time, status) ~ sex, data = lung)
p1 = ggsurvplot(fitKM, data = lung)
p2 = ggadjustedcurves(fitCox, data = lung,variable = "sex")

When I do :

arrange_ggsurvplots(x = list(p1,p2))

I have

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error in FUN(X[[i]], ...) : An object of class ggsurvplot is required.

How can I do this ?

>Solution :

A ggsurvplot object is a list where the plot of the survival curves is stored as an element named plot which is ggplot object, whereas ggadjustedcurves returns a ggplot object by default.

Hence, one option to combine both plots would be to use one of the available options for ggplot objects like e.g. patchwork:

library(survminer)
library(survival)

fitKM  <- survfit(Surv(time, status) ~ sex, data = lung)
fitCox <- coxph(Surv(time, status) ~ sex, data = lung)
p1 = ggsurvplot(fitKM, data = lung)
p2 = ggadjustedcurves(fitCox, data = lung, variable = "sex")

library(patchwork)

p1$plot + p2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading