R包:gtsummary提供学术发表级的表格
2021-11-24 本文已影响0人
生信学习者2
介绍
在学术发表过程中,经常会出现特别好看的各种表格,如图所示。如果能有包直接生成这样的表格多好。现在gtsummary包提供了这样一个功能。更多知识分享请到 https://zouhua.top/。
导入R包
install.packages("gtsummary")
library(gtsummary)
library(tidyverse)
head(trial)
表格:测试1
# make dataset with a few variables to summarize
trial2 <- trial %>% select(age, grade, response, trt)
# summarize the data with our package
tbl_summary(trial2)
表格:测试2
tbl_summary(
trial2,
by = trt, # split table by group
missing = "no" # don't list missing data separately
) %>%
add_n() %>% # add column with total number of non-missing observations
add_p() %>% # test for a difference between groups
modify_header(label = "**Variable**") %>% # update the column header
bold_labels()
添加回归结果
mod1 <- glm(response ~ trt + age + grade, trial, family = binomial)
t1 <- tbl_regression(mod1, exponentiate = TRUE)
library(survival)
# build survival model table
t2 <- coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
tbl_regression(exponentiate = TRUE)
# merge tables
tbl_merge_ex1 <-
tbl_merge(
tbls = list(t1, t2),
tab_spanner = c("**Tumor Response**", "**Time to Death**")
)
Reference
参考文章如引起任何侵权问题,可以与我联系,谢谢。