Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change risk table order #213

Open
saskia-c opened this issue May 21, 2024 · 2 comments
Open

Change risk table order #213

saskia-c opened this issue May 21, 2024 · 2 comments

Comments

@saskia-c
Copy link

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!

@ddsjoberg
Copy link
Collaborator

Dear @saskia-c , That seems to be a very reasonable expectation! Thanks for the post

@MichaelDismorrMD
Copy link

MichaelDismorrMD commented Jul 11, 2024

@saskia-c A temporary fix is to adjust the levels in plotobject$data$strata.
E.g. plot$data$strata <- forcats::fct_rev(plot$data$strata)
The order of the factor levels there seem to decide the order in the risk table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants