kna123
kna123

Reputation: 125

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?

Upvotes: 0

Views: 799

Answers (2)

AnthonyC
AnthonyC

Reputation: 695

The object ggcompetingrisks(fit) is a ggplot object.

I didn't know you could do this, but apparently you can just facet it again.

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

Cumulative incidence plot

Upvotes: 0

pascal
pascal

Reputation: 1085

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

Upvotes: 1

Related Questions