英文:
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
Error in FUN(X[[i]], ...) : An object of class ggsurvplot is required.
How can I do this?
英文:
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 ?
答案1
得分: 1
A ggsurvplot
对象是一个 list
,其中存储了生存曲线的绘图,命名为 plot
,它是一个 ggplot
对象,而 ggadjustedcurves
默认返回一个 ggplot
对象。
因此,将这两个图表组合在一起的一个选项是使用 ggplot
对象的可用选项之一,例如 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
英文:
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
<!-- -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论