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

问题描述 投票:0回答:2

以下是示例代码:

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,  100,replace=TRUE), 1:6,
                  c('BRCA','LUNG','OV','CANCER','AIDS','HEART'))

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

ggcompetingrisks(fit)

R 自动生成一个 3 列、2 行的图。我希望将其排列为两列三行。有没有办法处理 ggcompetingrisks,或者我必须从头开始绘制所有内容?

r survival
2个回答
1
投票

据我所知,没有任何选项可以执行此操作。这意味着您应该更改功能代码:

  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


0
投票

对象

ggcompetingrisks(fit)
是一个 ggplot 对象。

我不知道你能做到这一点,但显然你可以再次分面。

ggcompetingrisks(fit) + facet_wrap(~group, ncol = 2)

Cumulative incidence plot

© www.soinside.com 2019 - 2024. All rights reserved.