Survminer – 排列多个 ggsurvplot 和 ggadjustedcurves

huangapple go评论74阅读模式
英文:

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  &lt;- survfit(Surv(time, status) ~ sex, data = lung)
fitCox &lt;- coxph(Surv(time, status) ~ sex, data = lung)
p1 = ggsurvplot(fitKM, data = lung)
p2 = ggadjustedcurves(fitCox, data = lung,variable = &quot;sex&quot;)

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

Survminer – 排列多个 ggsurvplot 和 ggadjustedcurves

英文:

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  &lt;- survfit(Surv(time, status) ~ sex, data = lung)
fitCox &lt;- coxph(Surv(time, status) ~ sex, data = lung)
p1 = ggsurvplot(fitKM, data = lung)
p2 = ggadjustedcurves(fitCox, data = lung, variable = &quot;sex&quot;)

library(patchwork)

p1$plot + p2

Survminer – 排列多个 ggsurvplot 和 ggadjustedcurves<!-- -->

huangapple
  • 本文由 发表于 2023年4月6日 23:02:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定