Skip to content

add_variable_grouping need same variable order as input table. #110

@JohannesNE

Description

@JohannesNE

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)

Metadata

Metadata

Assignees

No one assigned

    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