gtreg
gtreg copied to clipboard
tbl_ae* display rowwise
A feature request to display adverse event reporting by strata on multiple rows rather than separate columns. This could be useful for tables that get very wide.
Here is some quick starter code, but some details would need to be worked out with row ordering.
library(gtreg)
library(tidyverse)
# build AE tables stratified by treatment
tbl <-
df_patient_characteristics$trt %>%
unique() %>%
map(
~tbl_ae(
df_adverse_events %>% filter(trt %in% .x, system_organ_class == "Gastrointestinal disorders"),
id = patient_id,
id_df = df_patient_characteristics %>% filter(trt %in% .x),
ae = adverse_event,
soc = system_organ_class,
statistic = "{n} ({p}%)",
by = grade
) %>%
gtsummary::modify_table_body(
function(table_body) table_body %>% mutate(strata = .x, .after = label)
) %>%
modify_header(all_ae_cols() ~ "**Grade {by}**") %>%
modify_spanning_header(everything() ~ NA)
)
tbl_final <- tbl[[1]]
tbl_final$table_body <-
map(tbl, "table_body") %>%
bind_rows() %>%
group_by(variable, label) %>%
arrange(strata) %>%
ungroup()
tbl_final %>%
bold_labels() %>%
modify_header(strata = "**Arm**")
see phuse documentation for other possible rowwise tables