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"))
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"
)
Created on 2022-07-28 by the reprex package (v2.0.1)