Assists in patching together more complex tables. tbl_stack() appends two
or more gtsummary tables.
tbl_stack(
tbls,
group_header = NULL,
quiet = FALSE,
attr_order = seq_along(tbls),
tbl_ids = NULL,
tbl_id_lbls = NULL
)(list)
List of gtsummary objects
(character)
Character vector with table headers where length matches the length of tbls
(scalar logical)
Logical indicating whether to suppress additional messaging. Default is FALSE.
(integer)
Set the order table attributes are set.
Tables are stacked in the order they are passed in the tbls argument:
use attr_order to specify the order the table attributes take precedent.
For example, to use the header from the second table specify attr_order=2.
Default is to set precedent in the order tables are passed.
(character)
Optional character vector of IDs that will be assigned to the input tables.
The ID is assigned by assigning a name to the tbls list, which is
returned in x$tbls.
(vector)
Optional vector of the same length tbls.
When specified a new, hidden column is added to the returned .$table_body
with these labels. The most common use case of this argument is for
the development of other functions.
A tbl_stack object
# Example 1 ----------------------------------
# stacking two tbl_regression objects
t1 <-
glm(response ~ trt, trial, family = binomial) %>%
tbl_regression(
exponentiate = TRUE,
label = list(trt ~ "Treatment (unadjusted)")
)
t2 <-
glm(response ~ trt + grade + stage + marker, trial, family = binomial) %>%
tbl_regression(
include = "trt",
exponentiate = TRUE,
label = list(trt ~ "Treatment (adjusted)")
)
tbl_stack(list(t1, t2))
Characteristic
OR
95% CI
p-value
Abbreviations: CI = Confidence Interval, OR = Odds Ratio
# Example 2 ----------------------------------
# stacking two tbl_merge objects
library(survival)
t3 <-
coxph(Surv(ttdeath, death) ~ trt, trial) %>%
tbl_regression(
exponentiate = TRUE,
label = list(trt ~ "Treatment (unadjusted)")
)
t4 <-
coxph(Surv(ttdeath, death) ~ trt + grade + stage + marker, trial) %>%
tbl_regression(
include = "trt",
exponentiate = TRUE,
label = list(trt ~ "Treatment (adjusted)")
)
# first merging, then stacking
row1 <- tbl_merge(list(t1, t3), tab_spanner = c("Tumor Response", "Death"))
row2 <- tbl_merge(list(t2, t4))
tbl_stack(list(row1, row2), group_header = c("Unadjusted Analysis", "Adjusted Analysis"))
OR
95% CI
p-value
HR
95% CI
p-value
Unadjusted Analysis
Adjusted Analysis
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio