我对gtsummary
软件包以及如何设置默认主题有疑问:
DF:
library(tidyverse)
library(gtsummary)
library(gapminder)
gap <- gapminder %>%
dplyr::mutate_all(~ifelse(
sample(c(TRUE, FALSE), size = length(.), replace = TRUE, prob = c(0.8, 0.2)),
as.character(.),
NA)
) %>%
dplyr::mutate_at(vars(year:gdpPercap), ~as.numeric(.)
)
my_theme <-
list(
"tbl_summary-str:default_con_type" = "continuous2",
"tbl_summary-str:continuous_stat" = c("{median} ({p25} - {p75})",
"{mean} ({sd})",
"{min} - {max}",
"{N_miss} ({p_miss}%)"),
"tbl_summary-str:categorical_stat" = "{n} / {N} ({p}%)",
"style_number-arg:big.mark" = ""
)
gtsummary::set_gtsummary_theme(my_theme)
gap[, -1] %>%
gtsummary::tbl_summary(
# remove default missing values because we specified them in
# the theme above already
missing = "no"
)
当我将大洲作为分类变量并且未显示包含大洲摘要统计信息的表时,以上内容给我一个错误。我是否必须在tbl_summary
函数中指定一些自变量,还是必须在主题函数中添加/删除一些自变量?谢谢!
答案 0 :(得分:1)
非常感谢您报告此意外行为。这确实是一个错误,并且已在开发版本(可以从github安装)中修复。
remotes::install_github("ddsjoberg/gtsummary", quiet = TRUE)
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.3.5.9003'
my_theme <-
list(
"tbl_summary-str:default_con_type" = "continuous2",
"tbl_summary-str:continuous_stat" = c("{median} ({p25} - {p75})", "{mean} ({sd})"),
"tbl_summary-str:categorical_stat" = "{n} / {N} ({p}%)"
)
set_gtsummary_theme(my_theme)
tbl <-
gapminder::gapminder[, 2:3] %>%
tbl_summary()
由reprex package(v0.3.0)于2020-10-25创建