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
Error in FUN(X[[i]], ...) : An object of class ggsurvplot is required.
How can I do this ?
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