Skip to contents

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_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_bold_labels() applies automatically gtsummary::bold_labels() to all tables generated with gtsummary.

Examples

# \donttest{
library(gtsummary)

trial |>
  tbl_summary(include = c(grade, age), by = trt) |>
  add_p()
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
p-value2
Grade

0.9
    I 35 (36%) 33 (32%)
    II 32 (33%) 36 (35%)
    III 31 (32%) 33 (32%)
Age 46 (37, 60) 48 (39, 56) 0.7
    Unknown 7 4
1 n (%); Median (Q1, Q3)
2 Pearson’s Chi-squared test; Wilcoxon rank sum test
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()
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
p-value2
Grade

>0.9
    I 35.7% (35) 32.4% (33)
    II 32.7% (32) 35.3% (36)
    III 31.6% (31) 32.4% (33)
Age 47.0 (14.7) 47.4 (14.0) 0.8
    Unknown 7 4
1 % (n); Mean (SD)
2 Fisher’s Exact Test for Count Data with simulated p-value (based on 2000 replicates); Welch Two Sample t-test
# } # \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()
Characteristic Overall
N = 6,194
1
No
N = 2,236
1
Yes
N = 3,958
1
stype


    E 71.4% (4,421) 53.4% (1,194) 81.5% (3,227)
    H 12.2% (755) 23.0% (513) 6.1% (242)
    M 16.4% (1,018) 23.7% (529) 12.3% (489)
both 64.0% (3,825) 0.0% (0) 100.0% (3,825)
    Unknown 221 88 133
1 % (n)
theme_gtsummary_unweighted_n() apistrat |> srvyr::as_survey(strata = stype, weights = pw) |> tbl_svysummary(include = c(stype, both), by = awards) |> add_overall()
Characteristic Overall (200 obs.)1 No (200 obs.)1 Yes (200 obs.)1
stype


    E 71.4% (100 obs.) 53.4% (27 obs.) 81.5% (73 obs.)
    H 12.2% (50 obs.) 23.0% (34 obs.) 6.1% (16 obs.)
    M 16.4% (50 obs.) 23.7% (26 obs.) 12.3% (24 obs.)
both 64.0% (110 obs.) 0.0% (0 obs.) 100.0% (110 obs.)
    Unknown 5 obs. 2 obs. 3 obs.
1 % (n (unweighted) obs.)
# } gtsummary::reset_gtsummary_theme()