I have a composite variable ("Needs Medical Attention") that is made up of several sub-variables ("Heart Disease", "Cancer"); that is, if a subject has "Heart Disease" or "Cancer", they are flagged for "Needs Medical Attention". In my presentation of these variables, I would like to visually suggest that "Heart Disease" and "Cancer" are sub-categories of "Needs Medical Attention".
In the past, I have used kableExtra() to print tables where I'm then able to add indents to certain rows using add_indent(c(rows_that_want_indented)). I'd love an equivalent for tbl_summary, but I'm unable to.
I've tried just adding spaces (" ") to the beginning of my variable labels to blunt force it, but these empty spaces aren't recognized. I've also tried using " " and a bunch of its varieties with various numbers of backslashes (\), but with no luck.
library("tidyverse")
library("gtsummary")
sim_data <- data.frame(
number = rnorm(20),
heart_disease = c(rep(0, 10), rep(1, 10)),
cancer = c(rep(1, 5), rep(0, 5), rep(1, 5), rep(0, 5))
)
sim_data$need_medical_attention <- with(sim_data, ifelse(heart_disease == 1 | cancer == 1, 1, 0))
tbl_summary(data = sim_data,
include = c(
number,
need_medical_attention,
heart_disease,
cancer
),
label = list(
number = "Number",
need_medical_attention = "Needs Medical Attention",
heart_disease = " Heart disease",
cancer = " Cancer"
))
Lastly, I've also messed around with modify_table_styling() using text_format = "indent", but I think this just refers to rows that have sub-rows that are indented (like rows with continuous statistical summaries, i.e. mean and variance or median and IQR).
How can I indent these rows?
(Note: I am not dealing with categories of categorical variables that need to be indented. I'm dealing with entire variables).