Skip to content

Change risk table order #213

@saskia-c

Description

@saskia-c

When plotting a cuminc() plot and adding a risk table, the order of the strata in the risk table is alphabetical. Is it possible for the order to follow the levels of a factor?

In the example below, I would like Drug B to be the top row in the risk table, and Drug A to come second.
It seems by default the risk table does not follow the levels of the factored stratum.

# data
trial_new <- trial %>%
  mutate(trt = factor(trt,
                      levels = c("Drug B", "Drug A"),
                      labels = c("Drug B", "Drug A")),
         cr_response = ifelse(response == 1, 1, death*2))

# plot
cuminc(Surv(ttdeath, factor(cr_response)) ~ trt, data = trial_new) %>%
  ggcuminc() +
  add_risktable(risktable_stats = "{n.risk} ({cum.event})") 

Not sure if this a bug or a missing feature, but any help on this would be greatly appreciated. Many thanks!

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions