Learn R Programming

guideR (version 0.8.1)

gtsummary_themes: Themes for gtsummary

Description

Additional themes for tables generated with gtsummary.

Usage

theme_gtsummary_prop_n(
  prop_stat = "{p}% ({n})",
  prop_digits = 1,
  mean_sd = FALSE,
  cont_digits = 1,
  set_theme = TRUE
)

theme_gtsummary_fisher_simulate_p(set_theme = TRUE)

theme_gtsummary_unweighted_n( n_unweighted_prefix = "", n_unweighted_suffix = " obs.", prop_digits = 1, mean_sd = FALSE, cont_digits = 1, overall_string = NULL, set_theme = TRUE )

theme_gtsummary_bold_labels(set_theme = TRUE)

Arguments

prop_stat

(character)
Statistics to display for categorical variables (see gtsummary::tbl_summary()).

prop_digits

(non-negative integer)
Define the number of decimals to display for proportions.

mean_sd

(scalar logical)
Also, set default summary statistics to mean and standard deviation in gtsummary::tbl_summary(). Default is FALSE.

cont_digits

(non-negative integer)
Define the number of decimals to display for continuous variables.

set_theme

(scalar logical)
Logical indicating whether to set the theme. Default is TRUE. When FALSE the named list of theme elements is returned invisibly

n_unweighted_prefix, n_unweighted_suffix

(character)
Prefix and suffix displayed before and after the unweighted number of observations.

overall_string

(character)
Optional string to name the overall column.

Details

theme_gtsummary_prop_n() displays, by default, proportions before the number of observations (between brackets). This function cannot be used simultaneously with gtsummary::theme_gtsummary_mean_sd(), but you can use the mean_sd = TRUE option of theme_gtsummary_prop_n(). theme_gtsummary_prop_n() also modifies default method for gtsummary::add_ci.tbl_summary() ("wilson" for categorical variables, "t.test", i.e. mean confidence interval, for continuous variables if mean_sd = TRUE, "wilcox.test", i.e. confidence interval of the pseudomedian, for continuous variables if mean_sd = FALSE). Finally, theme_gtsummary_prop_n() also modifies default tests for gtsummary::add_p.tbl_summary() for continuous variables if mean_sd = TRUE ("t.test" for comparing 2 groups, or "oneway.test" for 3 groups or more). If mean_sd = FALSE, the default tests for continuous variables remain "wilcox.test" (2 groups) or "kruskal.test" (3 groups or more). For categorical variables, "chisq.test.no.correct" and "fisher.test" are used by default. See theme_gtsummary_fisher_simulate_p() to change the default test for categorical variables.

theme_gtsummary_fisher_simulate_p() modify the default test used for categorical variables by Fisher test, with computation of p-values by Monte Carlo simulation in larger than 2×2 tables.

theme_gtsummary_unweighted_n() modifies default values of tables returned by gtsummary::tbl_svysummary() and displays the unweighted number of observations instead of the weighted n. theme_gtsummary_unweighted_n() also modifies default method for gtsummary::add_ci.tbl_svysummary() ("svyprop.logit" for categorical variables, "svymean", i.e. mean confidence interval, for continuous variables if mean_sd = TRUE, "svymedian.mean", i.e. confidence interval of the median, for continuous variables if mean_sd = FALSE). Finally, theme_gtsummary_unweighted_n() also modifies default tests for gtsummary::add_p.tbl_svysummary() for continuous variables if mean_sd = TRUE (svyttest_oneway which calls survey::svyttest() for comparing 2 means and svyoneway() for comparing 3 means or more). If mean_sd = FALSE, the default tests for continuous variables remain "svy.wilcox.test" which used a designed-based Wilcoxon test (2 groups) or Kruskal-Wallis test (3 groups or more). For categorical variables, "svy.chisq.test"is used by default.

theme_gtsummary_bold_labels() applies automatically gtsummary::bold_labels() to all tables generated with gtsummary.

Examples

Run this code
if (FALSE) { # rlang::is_installed("gtsummary")
# \donttest{
library(gtsummary)

trial |>
  tbl_summary(include = c(grade, age), by = trt) |>
  add_p()

theme_gtsummary_prop_n(mean_sd = TRUE)
theme_gtsummary_fisher_simulate_p()
theme_gtsummary_bold_labels()
trial |>
  tbl_summary(include = c(grade, age), by = trt) |>
  add_p()
# }
}
if (FALSE) { # rlang::is_installed(c("gtsummary", "srvyr"))
# \donttest{
data("api", package = "survey")
apistrat$both[1:5] <- NA
apistrat |>
  srvyr::as_survey(strata = stype, weights = pw) |>
  tbl_svysummary(include = c(stype, both), by = awards) |>
  add_overall()

theme_gtsummary_unweighted_n()
apistrat |>
  srvyr::as_survey(strata = stype, weights = pw) |>
  tbl_svysummary(include = c(stype, both), by = awards) |>
  add_overall()
# }

gtsummary::reset_gtsummary_theme()
}

Run the code above in your browser using DataLab