I have a question regarding the gtsummary package and how to set a default theme:
DF:
library(tidyverse)
library(gtsummary)
library(gapminder)
gap <- gapminder %>%
dplyr::mutate_all(~ifelse(
sample(c(TRUE, FALSE), size = length(.), replace = TRUE, prob = c(0.8, 0.2)),
as.character(.),
NA)
) %>%
dplyr::mutate_at(vars(year:gdpPercap), ~as.numeric(.)
)
my_theme <-
list(
"tbl_summary-str:default_con_type" = "continuous2",
"tbl_summary-str:continuous_stat" = c("{median} ({p25} - {p75})",
"{mean} ({sd})",
"{min} - {max}",
"{N_miss} ({p_miss}%)"),
"tbl_summary-str:categorical_stat" = "{n} / {N} ({p}%)",
"style_number-arg:big.mark" = ""
)
gtsummary::set_gtsummary_theme(my_theme)
gap[, -1] %>%
gtsummary::tbl_summary(
# remove default missing values because we specified them in
# the theme above already
missing = "no"
)
The above gives me an error when I include the continent as a categorical variable and does not display a table with summary statistics for the continent. Do I have to specify some arguments in the tbl_summary function or do I have to add/remove some arguments in the theme function? Thank you!
