Learn R Programming

⚠️There's a newer version (1.6.3) of this package.Take me there.

gtsummary

The {gtsummary} package provides an elegant and flexible way to create publication-ready and reproducible analytical tables. The tables summarize data sets, regression models, and more. The code is concise and the tables are highly customizable. Data frames can be summarized with any function, e.g. mean(), median(), even user-written functions. Regression models are summarized and include the reference rows for categorical variables. Common regression models, such as logistic regression and Cox proportional hazards regression, are automatically identified and the tables are pre-filled with appropriate column headers (i.e. Odds Ratio, and Hazard Ratio). The package uses {broom} to perform initial tidying of the regression models, which means there is broad support for many types of regression models.

{gtsummary} uses the {gt} package enabling each table to be tailored to your preferences. If you label your data (which I recommend!), the labels will be used in the table output. With {gtsummary} and {labelled} data, you get beautifully formatted, ready-to-share tables in a single line of code! Check out the examples below, and review the vignettes for a detailed exploration of the output options.

Installation

The {gtsummary} package was written as a companion to the {gt} package from RStudio, and it is recommended to install both {gt} and {gtsummary}. The {gt} package is not automatically installed. If {gt} is not installed, knitr::kable() will be used to produce the summary tables. You can install {gtsummary} and {gt} with the following code.

  1. Install {gtsummary}

    install.packages("gtsummary")
  2. Install {gt} from GitHub (recommended)

    install.packages("remotes")
    remotes::install_github("rstudio/gt")
    • If you experience issues installing {gt} on Windows, install Rtools from CRAN, restart R, and attempt installation again.

Install the development version of {gtsummary} with:

remotes::install_github("ddsjoberg/gtsummary")

Examples

The {gtsummary} vignettes/tutorials contain detailed examples.

Summary Table

library(gtsummary)
t1 <-
  tbl_summary(
    data = trial[c("trt", "age", "grade", "response")],
    by = trt
  ) %>%
  add_p() 

Regression Models

mod1 <- 
  glm(response ~ trt + age + grade, trial, family = binomial(link = "logit"))

t2 <- tbl_regression(mod1, exponentiate = TRUE)

Other Tables

Side-by-side regression model results from tbl_merge()

Survival Estimates from tbl_survival()

Print Engine

{gtsummary} uses the {gt} package to print all summary tables. In addition to supporting {gt}, the {gtsummary} package works well with knitr::kable(). This is particularly useful when outputting documents to Microsoft Word. If the {gt} package is not installed, {gtsummary} will fall back to knitr::kable(). To explicitly set the printing engine, set the option in the script or in the user- or project R profile, .Rprofile.

options(gtsummary.print_engine = "kable") 

or

options(gtsummary.print_engine = "gt")

Output from kable is less full featured compared to summary tables produced with {gt}. For example, kable summary tables do not include indentation, footnotes, and spanning header rows.

Contributing

Please note that the {gtsummary} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms. A big thank you to all contributors!
@ablack3, @ahinton-mmc, @ddsjoberg, @emilyvertosick, @jennybc, @jflynn264, @karissawhiting, @margarethannum, @michaelcurry1123, @sammo3182, and @zabore

Copy Link

Version

Install

install.packages('gtsummary')

Monthly Downloads

41,884

Version

1.2.1

License

MIT + file LICENSE

Maintainer

Daniel D. Sjoberg

Last Published

August 20th, 2019

Functions in gtsummary (1.2.1)

bold_p.tbl_regression

Bold significant p-values or q-values
assign_var_label

Assigns variable label to display.
as_kable

Convert to knitr_kable object
inline_text

Report statistics from gtsummary tables inline
gtsummary_logo

The gtsummary logo, using ASCII or Unicode characters
sort_p

Sort variables in table by ascending p-values
bold_p.tbl_summary

Bold significant p-values or q-values
bold_p.tbl_uvregression

Bold significant p-values or q-values
add_overall

Add column with overall summary statistics
sort_p.tbl_regression

Sort variables in table by ascending p-values
bold_p.tbl_stack

Bold significant p-values or q-values
select_helpers

Select helper functions
reexports

Objects exported from other packages
add_stat_label

Add statistic labels column
as_gt

Convert gtsummary object to a gt_tbl object
inline_text.tbl_survival

Report statistics from survival summary tables inline
sort_p.tbl_summary

Sort variables in table by ascending p-values
add_q.tbl_summary

Add a column of q-values to account for multiple comparisons
tbl_merge

Merge two or more gtsummary regression objects
inline_text.tbl_uvregression

Report statistics from regression summary tables inline
tbl_regression

Display regression model results in table
tbl_survival.survfit

Creates table of survival probabilities
tbl_survival

Creates table of univariate summary statistics for time-to-event endpoints
bold_italicize_labels_levels

Bold or Italicize labels or levels in gtsummary tables
bold_p

Bold significant p-values or q-values
gtsummary-package

gtsummary: Presentation-Ready Data Summary and Analytic Result Tables
deprecated

Deprecated functions
inline_text.tbl_regression

Report statistics from regression summary tables inline
add_q.tbl_uvregression

Add a column of q-values to account for multiple comparisons
inline_text.tbl_summary

Report statistics from summary tables inline
sort_p.tbl_uvregression

Sort variables in table by ascending p-values
modify_header

Modify column headers in gtsummary tables
print_gtsummary

print and knit_print methods for gtsummary objects
tbl_stack

Stacks two or more gtsummary regression objects
tbl_summary

Create a table of summary statistics
trial

Results from a simulated trial of Placebo vs Drug
tbl_uvregression

Display univariate regression model results in table
style_pvalue

Style p-values to be displayed in tables or text
style_percent

Style percentages to be displayed in tables or text
style_sigfig

Implement significant figure-like rounding
style_ratio

Implement significant figure-like rounding for ratios
add_global_p

Adds the global p-value for a categorical variables
add_nevent.tbl_uvregression

Add number of events to a regression table
add_nevent

Add number of events to a regression table
add_global_p.tbl_uvregression

Adds the global p-value for categorical variables
add_global_p.tbl_regression

Adds the global p-value for categorical variables
add_p

Adds p-values to summary tables
add_n

Add column with N
add_nevent.tbl_regression

Add number of events to a regression table
add_q

Add a column of q values to account for multiple comparisons