MSKCC-Epi-Bio/bstfun

`add_variable_grouping` need same variable order as input table.

JohannesNE opened this issue · 2 comments

add_variable_grouping is a great addition to gtsummary. I hope it will move into the main package soon.

I found that the order of the variables for the grouping need to match the order in the original input table.
The problem was not immediately obvious to me, so maybe add a warning if it is not an easy fix.

library(bstfun)

set.seed(11234)
data.frame(
    race_asian = sample(c(TRUE, FALSE), 20, replace = TRUE),
    race_black = sample(c(TRUE, FALSE), 20, replace = TRUE),
    race_white = sample(c(TRUE, FALSE), 20, replace = TRUE),
    age = rnorm(20, mean = 50, sd = 10)
  ) %>%
  gtsummary::tbl_summary(
    label = list(race_asian = "Asian",
                 race_black = "Black",
                 race_white = "White",
                 age = "Age")
  ) %>%
  add_variable_grouping(
    "Race (check all that apply)" = 
      c(
        "race_black",
        "race_asian", # <--- Should be first
        "race_white"
        )
  ) |> 
  as_ggplot() # to show output

Created on 2022-07-01 by the reprex package (v2.0.0)

Thanks for the post @JohannesNE !

I am trying to take a bit of a dev break at the moment. Happy to review a pull request for this issue, however!

Fair ☺️ I'm trying to write a PhD dissertation, so unfortunately i do to habe time to dive more into this atm.