设置 Overall 列以报告 gtsummary 中的列百分比
Setting the Overall column to report column percentage in gtsummary
我希望总体具有列百分比,而其他列报告行百分比。一个人会怎么做。提前致谢。
library(gtsummary)
library(dplyr)
trial %>%
select(age, grade, response, trt) %>%
tbl_summary(by=trt, percent = "row",
type = response ~ "categorical",
missing = "no") %>%
add_overall()
add_overall()
的结果将始终与 tbl_summary()
中的调用一致。为了得到你想要的,建立两个表并合并它们。示例如下!
library(gtsummary)
tbl_row_percent <-
trial %>%
select(age, grade, response, trt) %>%
tbl_summary(by=trt, percent = "row",
type = response ~ "categorical",
missing = "no")
tbl_col_percent <-
trial %>%
select(age, grade, response) %>%
tbl_summary(type = response ~ "categorical",
missing = "no") %>%
modify_header(all_stat_cols() ~ "**Overall**, N = {N}")
tbl_final <-
tbl_merge(list(tbl_col_percent, tbl_row_percent)) %>%
modify_spanning_header(everything() ~ NA)
由 reprex package (v2.0.1)
于 2021-08-24 创建
我希望总体具有列百分比,而其他列报告行百分比。一个人会怎么做。提前致谢。
library(gtsummary)
library(dplyr)
trial %>%
select(age, grade, response, trt) %>%
tbl_summary(by=trt, percent = "row",
type = response ~ "categorical",
missing = "no") %>%
add_overall()
add_overall()
的结果将始终与 tbl_summary()
中的调用一致。为了得到你想要的,建立两个表并合并它们。示例如下!
library(gtsummary)
tbl_row_percent <-
trial %>%
select(age, grade, response, trt) %>%
tbl_summary(by=trt, percent = "row",
type = response ~ "categorical",
missing = "no")
tbl_col_percent <-
trial %>%
select(age, grade, response) %>%
tbl_summary(type = response ~ "categorical",
missing = "no") %>%
modify_header(all_stat_cols() ~ "**Overall**, N = {N}")
tbl_final <-
tbl_merge(list(tbl_col_percent, tbl_row_percent)) %>%
modify_spanning_header(everything() ~ NA)