I am working with a large data set, and in the following example, I would like to indent the numerical variables (Scores, Time, and Grade), bold the levels of color (“Blue”, “Green”, etc.), provide p-values with 3 digits, and bold those p-values < 0.5. Thanks!
library(gtsummary)
library(tidyverse)
df <- data.frame(group = c("Control", "Intervention"),
level = c("Low", "Moderate", "High"),
color = rep(c("Green", "Yellow", "Red",
"Blue", "White", "Purple"),
each = 6),
Scores = runif(n = 180,
min = 100,
max = 1000),
Time = runif(n = 180,
min = 0.5,
max = 1),
Grade = runif(n = 180,
min = 1,
max = 10)
)
list("tbl_summary-fn:addnl-fn-to-run" =
function(x) {
if (!is.null(x$by)) x <- add_p(x)
italicize_labels(x)
}
) |>
set_gtsummary_theme()
tbl <- df |>
tbl_strata(strata = color,
function(df) {
df |>
tbl_strata(strata = level,
~ tbl_summary(.x,
by = group,
statistic = all_continuous() ~ "{mean} ({sd})"
) )
},
.combine_with = "tbl_stack") |>
modify_header(label ~ "")
tbl