0

I'm new to gtsummary (thanks to the developers for such a great package!).

I've used tbl_stack to stack two tables from my "malawi" dataset- one with stats summarised as Medians ("baselines_eg" baselines_eg_pic), and one with stats summarised as Means ("bloods_eg" bloods_eg_pic). tbl_stack automatically uses the headers and footer for the first object only when combined (combined_tables). However, as they're different tests used I wanted to have both within the footnote, without it looking messy.

I tried using modify_table_styling but that seems to limit to number of rows allowed (and doesn't look 'nice'); I tried using add_stat_label to the second object but again it doesn't 'look nice.'

Is there a way that I can add the superscript number to the second table's group_header and footnote it neatly please (and preferably in an easily reproduceable way for future possible stacks?).

Many thanks.

Edited to add examples.

baselines_eg <- malawi %>% 
  dplyr::select(ptsex, calc_age, days_unwell) %>% 
  tbl_summary(by = ptsex, missing = "no",
              label = list(
                ptsex ~ "Sex", 
                calc_age ~ "Age",
                days_unwell ~ "Days Unwell")) %>% 
              modify_header(label ~ "**Variable**") %>% 
  modify_caption("**Table X. Patient Characteristics**") %>% 
  modify_header(all_stat_cols() ~ "**{level}**<br>N = {n} ({style_percent(p)}%)")

bloods_eg <- malawi %>% 
  dplyr::select(ptsex, Haemoglobin, Haematocrit, MCV, Platelets) %>% 
  tbl_summary(by = ptsex, missing = "no",
              statistic = list(Haemoglobin ~ "{mean} ({sd})",
                               Haematocrit ~ "{mean} ({sd})",
                               MCV ~ "{mean} ({sd})", 
                               Platelets ~ "{mean} ({sd})"), 
                label = list(
                ptsex ~ "Sex", 
                Haemoglobin ~ "Haemoglobin (g/dL)",
                Haematocrit ~ "Haematocrit (L/L)",
                Platelets ~ "Platelets (10^9^/L)")) %>%
  modify_header(label ~ "**Variable**") %>% 
  #add_stat_label() %>% 
  modify_caption("**Table X. Sequenced Patient Characteristics**") %>% 
  modify_header(all_stat_cols() ~ "**{level}**<br>N = {n} ({style_percent(p)}%)")


tbl_stack(list(baselines_eg, bloods_eg), group_header = c("Baseline Characteristics", "Blood Results")) %>% 
  as_gt() %>%
  gt::tab_style(
    style = gt::cell_text(weight = "bold"),
    locations = gt::cells_row_groups(groups = everything()))
Farah
  • 1
  • 1
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 27 '23 at 18:37

0 Answers0