【问题标题】:ggsurvplot and ggplot lattice ?! Plotting kaplan-meier curve with cumulative incidence functionggsurvplot 和 ggplot 格子?!绘制具有累积关联函数的 kaplan-meier 曲线
【发布时间】:2021-06-20 13:01:51
【问题描述】:

我想将卡普兰迈尔曲线 (KM) 和累积事件或累积关联函数 (CIF) 绘制为格子图。

我最近从 SAS 切换到 R,在 SAS 中,您可以使用宏一步完成所有操作(请参阅 this image),但我在 R 中找不到类似的东西。

目前,我为两个单独的图表运行代码。第一个使用ggsurvplot 绘制survfit 对象,这会产生一条KM 曲线,而第二个使用ggplot 在经过多次转换后绘制一个cuminc 对象。 ggcompetingrisks 不是很可优化,所以我不使用它。我也有兴趣绘制一种特定的竞争风险,例如癌症死亡,而不是所有竞争风险。

这是我当前使用 survminer 包中的 BMT 数据框的代码示例。

library(survminer)
library(cmprsk)
data(BMT)

# I'll add the variable Death to plot overall survival.
BMT <- mutate(BMT, death = ifelse (status == 1, 1, 0))

# KM plot:
figKM <- ggsurvplot(survfit(Surv(ftime, death) ~ dis, BMT))
figKM

# CIF plot:
cif <- cuminc(ftime = BMT$ftime, fstatus = BMT$status, group = BMT$dis, cencode = 0)
cifDT <- cif %>% 
  list_modify("Tests" = NULL) %>% 
  map_df(`[`, c("time", "est"), .id = "id")  %>% 
  filter(id %in% c("0 1","1 1")) # to keep the incident I want

figCIF <- ggplot (cifDT, aes(x = time, y = est, color = id)) + geom_step(lwd = 1.2)
figCIF

有没有办法将 figKM 和 figCIF 放在一个格子图中?可以通过不同的方式绘制它们吗?

【问题讨论】:

  • 你可能正在寻找 cowplot 包。
  • 它没有用。结果是一个空图。
  • 很难知道该评论是什么。当我运行你的代码时,我得到'找不到函数“map_df”'。
  • @IRTFM 好的,您可以使用 cowplot 包合并两个 KM 图形吗?当我这样做时,我得到的只是一个空的数字。

标签: r ggplot2 survival-analysis survminer


【解决方案1】:

如果您使用 classstr 查看 figKM 对象的内容,您会发现该列表中的第一项是“情节”,所以这似乎符合您在评论中要求的内容:

 library(cowplot)
 plot_grid(figKM[[1]], figKM[[1]], nrow = 2)

我不是 tidyverse 用户,所以 map_df 可能是基本函数 ReduceMap 的一些克隆,但我没有足够的经验来 a) 知道要加载哪个包,或者 b ) 有能力弄清楚你的管道表达式正在做什么。注释代码可能更容易理解。我对survival 包非常有经验。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-03
    • 2021-11-10
    • 1970-01-01
    • 2015-10-27
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多