View source: R/add_variable_group_header.R
add_variable_group_header | R Documentation |
Some data are inherently grouped, and should be reported together. Grouped variables are all indented together. This function indents the variables that should be reported together while adding a header above the group.
add_variable_group_header(x, header, variables, indent = 4L)
x |
( |
header |
( |
variables |
( |
indent |
( |
This function works by inserting a row into the x$table_body
and
indenting the group of selected variables.
This function cannot be used in conjunction with all functions in gtsummary;
for example, bold_labels()
will bold the incorrect rows after running
this function.
a gtsummary table
# Example 1 ----------------------------------
set.seed(11234)
data.frame(
exclusion_age = sample(c(TRUE, FALSE), 20, replace = TRUE),
exclusion_mets = sample(c(TRUE, FALSE), 20, replace = TRUE),
exclusion_physician = sample(c(TRUE, FALSE), 20, replace = TRUE)
) |>
tbl_summary(
label = list(exclusion_age = "Age",
exclusion_mets = "Metastatic Disease",
exclusion_physician = "Physician")
) |>
add_variable_group_header(
header = "Exclusion Reason",
variables = starts_with("exclusion_")
) |>
modify_caption("**Study Exclusion Criteria**")
# Example 2 ----------------------------------
lm(marker ~ trt + grade + age, data = trial) |>
tbl_regression() |>
add_global_p(keep = TRUE, include = grade) |>
add_variable_group_header(
header = "Treatment:",
variables = trt
) |>
add_variable_group_header(
header = "Covariate:",
variables = -trt
) |>
# indent levels 8 spaces
modify_indent(
columns = "label",
rows = row_type == "level",
indent = 8L
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.