这与?tbl_strata
帮助文件中的第二个示例非常相似.
.combine_args = list(group_header = NULL)
来 suppress 默认堆叠标头.tbl_strata2()
,将分层级别作为第二个参数,并添加此行以更新标签label = list(hwy = .y)
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.7.2'
data("mpg", package = "ggplot2")
mpg |>
select(hwy, cyl, manufacturer) |>
tbl_strata2(
strata = manufacturer,
~ .x |>
tbl_summary(
by = cyl,
type = list(hwy = "continuous"),
label = list(hwy = .y)
),
.combine_with = "tbl_stack",
.combine_args = list(group_header = NULL)
) |>
as_kable() # convert to kable to display on SO
#> ℹ Column headers among stacked tables differ. Headers from the first table are
#> used. Use `quiet = TRUE` to suppress this message.
Characteristic | 4, N = 8 | 6, N = 9 | 8, N = 1 |
---|---|---|---|
audi | 29 (27, 29) | 25 (25, 26) | 23 (23, 23) |
chevrolet | 29 (28, 29) | 26 (26, 28) | 20 (17, 24) |
dodge | 24 (24, 24) | 22 (18, 23) | 16 (15, 17) |
ford | 19 (17, 25) | 17 (17, 21) | |
honda | 32 (32, 34) | ||
hyundai | 28 (27, 29) | 25 (24, 26) | |
jeep | 20 (20, 21) | 17 (14, 18) | |
land rover | 17 (15, 18) | ||
lincoln | 17 (17, 18) | ||
mercury | 18 (18, 19) | 18 (18, 19) | |
nissan | 30 (29, 31) | 25 (19, 26) | 18 (18, 18) |
pontiac | 27 (26, 27) | 25 (25, 25) | |
subaru | 26 (25, 26) | ||
toyota | 30 (23, 31) | 20 (19, 26) | 17 (16, 18) |
volkswagen | 29 (29, 29) | 29 (29, 29) | 25 (24, 26) |
创建于2024年4月12日,共有reprex v2.1.0个