Search code examples
gtsummaryfootnotes

Is there a way of adding a footnote to a gtsummary table that will persist after merging with another table?


I have two tables 'tbl' that I have merged. I want to add a footnote to the final merged table, but it doesn't work for me. I've tried both adding it to the individual tables like so:

library(gtsummary)
packageVersion("gtsummary")

tbl <- 
  glm(response ~ grade, trial, family = binomial) %>% 
  tbl_regression(exponentiate = TRUE) %>%
  add_glance_table(include = nobs) %>%
  add_n(location = c("label", "level")) %>%
  modify_footnote(all_stat_cols() ~ "models")

And it works for the individual tables, but as soon as I merge them the footnote disappears.

I've tried adding it to the merged table like so, but without success:

tbl_final <- 
  tbl_merge(list(tbl, tbl), tab_spanner = c("**Men**", "**Women**")) %>%
modify_footnote(all_stat_cols() ~ "Models") 

How should I go about it? Thanks!


Solution

  • You are using all_stat_cols(), which is intended for use with tbl_summary() objects, rather than tbl_regression() tables. Use the show_header_names() function to print the column names to be able to place the footnotes on the columns you need, e.g. modify_footnote(estimate ~ "Odds Ratio")