0

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?

kna123
  • 115
  • 8

1 Answers1

1

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

pascal
  • 1,036
  • 5
  • 15
  • I didn't know you could do that (change the functions code)! That worked beautifully. Thank you. – kna123 Feb 10 '21 at 15:15