如何在 ggcompetingrisks 中指定图的布局?

问题描述

以下是示例代码

set.seed(2)
failure_time <- rexp(100)
status <- factor(sample(0:3,100,replace=TRUE),0:3,c('no event','death','progression','other'))
disease <- factor(sample(1:6,1:6,c('BRCA','LUNG','OV','CANCER','AIDS','HEART'))

fit <- cuminc(ftime = failure_time,fstatus = status,group = disease)

ggcompetingrisks(fit)

R 自动生成按 3 列、2 行组织的图。我希望将其排列为两列和三行。有没有办法处理 ggcompetingrisks,还是我必须从头开始绘制所有内容

解决方法

据我所知,没有任何选项可以做到这一点。这意味着您应该更改函数代码:

  1. 调用函数代码:

    trace(survminer:::ggcompetingrisks.cuminc,edit = T)

  2. 在第 23 行将 ncol = 2 添加到 facet_wrap(~group) 中,例如:

    pl <- ggplot(df,aes(time,est,color = event)) + facet_wrap(~group,ncol = 2)

  3. 正常绘图:

    ggcompetingrisks(fit)

enter image description here