5

I'm trying to add a footnote to a row label of a gtsummary table, but I can't figure out how to reference the exact cell I want.

Intended output

Usint the default trial dataset, I'd like to add a footnote to "Drug B" that reads "i.e. placebo":

Characteristic N = 200¹
Chemotherapy Treatment
__ Drug A 98 (49%)
__ Drug B² 102 (51%)
¹ n (%)
² i.e. placebo

I've tried converting to a gt table and then using tab_footnote() and cells_stub(), but I don't know how to use row = to reference the specific row label I want.

Unfortunately the documentation example for cells_stub() only uses its default locations = everything() argument value.

library(gtsummary)
library(gt)

trial["trt"] |>
        tbl_summary() |>
        as_gt() |>
        tab_footnote(footnote = "i.e. placebo",
                     # Line below doesn't work
                     locations = cells_stub(rows = "Drug B"))
Andrea M
  • 2,314
  • 1
  • 9
  • 27

1 Answers1

7

You can use the gtsummary::modify_table_styling() function to place footnotes in the body of a table. Example below!

library(gtsummary)

tbl <-
  trial |>
  select(trt) |> 
  tbl_summary() |>
  modify_table_styling(
    columns = label,
    rows = label == "Drug B",
    footnote = "i.e. placebo"
  )

enter image description here Created on 2022-07-28 by the reprex package (v2.0.1)

Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28