This might be a silly ask (or I'm overthinking it), but for the sake of formatting, I'm trying to create an empty variable name to then move rows around in a gtsummary table. The code is set up so that they are all individual, but I'd like for them to appear cohesive. In order to do this, I’ve been using a variable with no meaningful data and changing the name, then modifying the image through PowerPoint. I’d love to not have to do this every time I play with the figure.
(Also, if this doesn’t make sense, please just let me know!)
I’ve been trying to use modify_table_body()
to make a row blank, but nothing has worked.
Here's what my code looks like right now:
Demo_data <- nomed_data %>%
dplyr::select(
Total_DIS,
participantNum,
Total_PA,
Total_NA,
PA_NA,
PANA,
CoMorbidity = Final_questions.question2,
Gender = Consent.question10,
Age = Consent.question11,
group
) %>%
mutate(
# Relevel
Gender = factor(Gender, levels = c(1, 2, 3),
labels = c("Female", "Male", "Other")),
CoMorbidity = factor(CoMorbidity, levels = c(1, 2),
labels = c("Yes", "No"))
)
# install.packages("gtsummary")
library(gtsummary)
theme_gtsummary_compact()
Demo_data |>
tbl_summary(
by = group,
type = all_continuous() ~ "continuous",
statistic = all_continuous() ~ "{mean} ({sd})",
label = list(
Total_DIS = "DIS",
participantNum = "Mood", # empty variable, use as header
Total_PA = "PA",
Total_NA = "NA",
PA_NA = "PA-NA",
PANA = "PA+NA",
CoMorbidity = "Differential Diagnoses",
Gender = "Gender",
Age = "Mean Age"
),
digits = list(all_continuous() ~ c(2, 2)),
missing = "ifany"
) |>
# add_p(pvalue_fun = label_style_pvalue(digits = 2)) |>
add_overall() |>
modify_header(label ~ "**Variable**") |>
modify_caption("**Table 1. Participant Characteristics**") |>
bold_labels() |>
modify_column_indent(
columns = label,
rows = label %in% c("PA", "NA", "PA+NA", "PA-NA"),
indent = 4L
) |>
modify_table_styling(
columns = label,
rows = label %in% c("PA", "NA", "PA+NA", "PA-NA"),
undo_text_format = c("bold")
) |>
modify_table_styling(
columns = label,
rows = label == "Unknown",
footnote = "Due to a technical glitch 92 people did not receive questions on age and gender"
)