使用gt函数对gtsummary合并表进行样式设置



我一直在使用as_gt()函数来格式化我的gtsummary表,这在每个单独的表上都能很好地工作。但是当试图合并表(tbl_merge)在一起这个错误出现:

Error: Error in argument 'x='. Expecting object of class 'gtsummary'

无论给每个单独的表提供gt格式选项,还是只给合并的对象提供,都会发生同样的错误。有什么办法吗?下面Repex。

library(survival)
library(tidyverse)
library(gt)
library(gtsummary)
# Works fine for individual tbls
t1 <-
glm(response ~ trt + grade + age, trial, family = binomial) %>%
tbl_regression(exponentiate = TRUE) %>%
as_gt() %>%
gt::tab_options(table.font.names = "Times New Roman")
t1
t2 <-
coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
tbl_regression(exponentiate = TRUE)
# Error appears
tbl_merge_ex1 <-
tbl_merge(
tbls = list(t1, t2),
tab_spanner = c("**Tumor Response**", "**Time to Death**") %>%
as_gt() %>%
gt::tab_options(table.font.names = "Times New Roman")
)
Error: Error in argument 'x='. Expecting object of class 'gtsummary'

您需要删除所有as_gt(),直到合并后的最后,如下所示:

library(survival)
library(tidyverse)
library(gt)
library(gtsummary)

t1 <-
glm(response ~ trt + grade + age, trial, family = binomial) %>%
tbl_regression(exponentiate = TRUE) 
t2 <-
coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
tbl_regression(exponentiate = TRUE)

tbl_merge_ex1 <-
tbl_merge(
tbls = list(t1, t2),
tab_spanner = c("**Tumor Response**", "**Time to Death**") 
) %>%
as_gt() %>%
gt::tab_options(table.font.names = "Times New Roman")

相关内容

  • 没有找到相关文章

最新更新