Search code examples
rsurvival

How do I specify the layout of plots in ggcompetingrisks?


Below is a sample code:

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 automatically generations a plot that is organized in 3 columns, 2 rows. I would like it to be arranged as two columns, and three rows. Is there a way to do with ggcompetingrisks, or would I have to plot everything from scratch?


Solution

  • There is no option that does this that I'm aware of. Meaning you should change the functions code:

    1. Call function code with:

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

    2. On line 23 add ncol = 2, to facet_wrap(~group) like:

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

    3. plot normally:

      ggcompetingrisks(fit)

    enter image description here