gtsummary

Presentation-Ready Data Summary and Analytic Result Tables

https://github.com/ddsjoberg/gtsummary

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 9 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.5%) to scientific vocabulary

Keywords

easy-to-use gt html5 r r-package regression-models reproducibility reproducible-research rstats statistics summary-statistics summary-tables table1 tableone

Keywords from Contributors

tidy-data data-manipulation rmarkdown grammar literate-programming pandoc book latex package-creation network-graph
Last synced: 6 months ago · JSON representation

Repository

Presentation-Ready Data Summary and Analytic Result Tables

Basic Info
Statistics
  • Stars: 1,139
  • Watchers: 18
  • Forks: 138
  • Open Issues: 65
  • Releases: 40
Topics
easy-to-use gt html5 r r-package regression-models reproducibility reproducible-research rstats statistics summary-statistics summary-tables table1 tableone
Created almost 7 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Support

README.Rmd

---
output: github_document
---



```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```


[![R-CMD-check](https://github.com/ddsjoberg/gtsummary/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ddsjoberg/gtsummary/actions/workflows/R-CMD-check.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/gtsummary)](https://cran.r-project.org/package=gtsummary)
[![Codecov test coverage](https://codecov.io/gh/ddsjoberg/gtsummary/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ddsjoberg/gtsummary?branch=main)
[![](https://cranlogs.r-pkg.org/badges/gtsummary)](https://cran.r-project.org/package=gtsummary)
[![DOI:10.32614/RJ-2021-053](https://zenodo.org/badge/DOI/10.32614/RJ-2021-053.svg)](https://doi.org/10.32614/RJ-2021-053)


## gtsummary 

The {gtsummary} package provides an elegant and flexible way to create publication-ready analytical and summary tables using the **R** programming language.  The {gtsummary} package summarizes data sets, regression models, and more, using sensible defaults with highly customizable capabilities.

* [**Summarize data frames or tibbles**](https://www.danieldsjoberg.com/gtsummary/articles/tbl_summary.html) easily in **R**. Perfect for presenting descriptive statistics, comparing group **demographics** (e.g creating a **Table 1** for medical journals),  and more. Automatically detects continuous, categorical, and dichotomous variables in your data set, calculates appropriate descriptive statistics, and also includes amount of missingness in each variable.

* [**Summarize regression models**](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) in R and include 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). 

* [**Customize gtsummary tables**](https://www.danieldsjoberg.com/gtsummary/reference/index.html#section-general-formatting-styling-functions) using a growing list of formatting/styling functions. **[Bold](https://www.danieldsjoberg.com/gtsummary/reference/bold_italicize_labels_levels.html)** labels, **[italicize](https://www.danieldsjoberg.com/gtsummary/reference/bold_italicize_labels_levels.html)** levels, **[add p-value](https://www.danieldsjoberg.com/gtsummary/reference/add_p.html)** to summary tables, **[style](https://www.danieldsjoberg.com/gtsummary/reference/style_percent.html)** the statistics however you choose, **[merge](https://www.danieldsjoberg.com/gtsummary/reference/tbl_merge.html)** or **[stack](https://www.danieldsjoberg.com/gtsummary/reference/tbl_stack.html)** tables to present results side by side... there are so many possibilities to create the table of your dreams! 

* **[Report statistics inline](https://www.danieldsjoberg.com/gtsummary/articles/inline_text.html)** from summary tables and regression summary tables in **R markdown**. Make your reports completely reproducible!



By leveraging [{broom}](https://broom.tidymodels.org/), [{gt}](https://gt.rstudio.com/), and [{labelled}](http://larmarange.github.io/labelled/) packages, {gtsummary} creates beautifully formatted, ready-to-share summary and result tables in a single line of R code!  

Check out the examples below, review the [vignettes](https://www.danieldsjoberg.com/gtsummary/articles/) for a detailed exploration of the output options, and view the [gallery](https://www.danieldsjoberg.com/gtsummary/articles/gallery.html) for various customization examples.


## Installation

The {gtsummary} package was written as a companion to the [{gt}](https://gt.rstudio.com/) package from RStudio.
You can install {gtsummary} with the following code.  

``` r
install.packages("gtsummary")
```

Install the development version with `pak::pkg_install("ddsjoberg/gtsummary", dependencies = TRUE)`

## Examples

### Summary Table

Use [`tbl_summary()`](https://www.danieldsjoberg.com/gtsummary/reference/tbl_summary.html) to summarize a data frame.

animated

Example basic table:

```{r table1, include = TRUE}
library(gtsummary)

# summarize the data with our package
table1 <-
  trial |> 
  tbl_summary(include = c(age, grade, response))
```

```{r tbl_summary_print_simple, include = FALSE}
# Had to manually save images in temp file, not sure if better way.
gt::gtsave(as_gt(table1), file = "man/figures/README-tbl_summary_print_simple-1.png")
```

```{r out.width = "25%", echo = FALSE}
knitr::include_graphics("man/figures/README-tbl_summary_print_simple-1.png")
```


There are many **customization options** to **add information** (like comparing groups) and **format results** (like bold labels) in your table. See the [`tbl_summary()`](https://www.danieldsjoberg.com/gtsummary/articles/tbl_summary.html) tutorial for many more options, or below for one example. 

```{r table2, include = TRUE}
table2 <-
  tbl_summary(
    trial,
    include = c(age, grade, response),
    by = trt, # split table by group
    missing = "no" # don't list missing data separately
  ) |> 
  add_n() |> # add column with total number of non-missing observations
  add_p() |> # test for a difference between groups
  modify_header(label = "**Variable**") |> # update the column header
  bold_labels()
```

```{r tbl_summary_print_extra, include = FALSE}
gt::gtsave(as_gt(table2), file = "man/figures/README-tbl_summary_print_extra-1.png")
```


```{r out.width = "55%", echo = FALSE}
knitr::include_graphics("man/figures/README-tbl_summary_print_extra-1.png")
```

### Regression Models

Use [`tbl_regression()`](https://www.danieldsjoberg.com/gtsummary/reference/tbl_regression.html) to easily and beautifully display regression model results in a table. See the [tutorial](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) for customization options.

```{r regress, include = TRUE}
mod1 <- glm(response ~ trt + age + grade, trial, family = binomial)

t1 <- tbl_regression(mod1, exponentiate = TRUE)
```

```{r tbl_regression_printa, include = FALSE}
gt::gtsave(as_gt(t1), file = "man/figures/README-tbl_regression_printa-1.png")
```


```{r out.width = "40%", echo = FALSE}
knitr::include_graphics("man/figures/README-tbl_regression_printa-1.png")
```

### Side-by-side Regression Models

You can also present side-by-side regression model results using `tbl_merge()`

```{r}
library(survival)

# build survival model table
t2 <-
  coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) |> 
  tbl_regression(exponentiate = TRUE)

# merge tables
tbl_merge_ex1 <-
  tbl_merge(
    tbls = list(t1, t2),
    tab_spanner = c("**Tumor Response**", "**Time to Death**")
  )
```

```{r tbl_merge_ex1, include = FALSE}
gt::gtsave(as_gt(tbl_merge_ex1), file = "man/figures/README-tbl_merge_ex1-1.png")
```


```{r out.width = "60%", echo = FALSE}
knitr::include_graphics("man/figures/README-tbl_merge_ex1-1.png")
```

Review even more output options in the **[table gallery](https://www.danieldsjoberg.com/gtsummary/articles/gallery.html)**.

## gtsummary + R Markdown

The **{gtsummary}** package was written to be a companion to the **{gt}** package from RStudio.
But not all output types are supported by the **{gt}** package.
Therefore, we have made it possible to print **{gtsummary}** tables with various engines.

Review the **[gtsummary + R Markdown](https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html)** vignette for details.


```{r out.width = "55%", echo = FALSE}
knitr::include_graphics("man/figures/gt_output_formats.PNG")
```


## Save Individual Tables

{gtsummary} tables can also be saved directly to file as an image, HTML, Word, RTF, and LaTeX file.

```r
tbl |> 
  as_gt() |> 
  gt::gtsave(filename = ".") # use extensions .png, .html, .docx, .rtf, .tex, .ltx
```

## Additional Resources

- The best resources are the gtsummary vignettes: [table gallery](https://www.danieldsjoberg.com/gtsummary/articles/gallery.html), [`tbl_summary()` tutorial](https://www.danieldsjoberg.com/gtsummary/articles/tbl_summary.html), [`tbl_regression()` tutorial](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html), [`inline_text()` tutorial](https://www.danieldsjoberg.com/gtsummary/articles/inline_text.html), [gtsummary themes](https://www.danieldsjoberg.com/gtsummary/articles/themes.html), [gtsummary+R markdown](https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html).
- The R Journal Article [*Reproducible Summary Tables with the gtsummary Package*](https://github.com/ddsjoberg/gtsummary/raw/main/data-raw/RJ-2021-053.pdf).
- The [RStudio Education Blog](https://education.rstudio.com/blog/2020/07/gtsummary/) includes a post with a brief introduction to the package. 
- A [recording of a presentation](https://www.youtube.com/watch?v=tANo9E1SYJE) given to the Weill Cornell Biostatistics Department and the Memorial Sloan Kettering R Users Group.

    

## Cite gtsummary

```{text, comment="", eval = FALSE}
> citation("gtsummary")

To cite gtsummary in publications use:

  Sjoberg DD, Whiting K, Curry M, Lavery JA, Larmarange J. Reproducible summary tables with the gtsummary package.
  The R Journal 2021;13:570–80. https://doi.org/10.32614/RJ-2021-053.

A BibTeX entry for LaTeX users is

  @Article{gtsummary,
    author = {Daniel D. Sjoberg and Karissa Whiting and Michael Curry and Jessica A. Lavery and Joseph Larmarange},
    title = {Reproducible Summary Tables with the gtsummary Package},
    journal = {{The R Journal}},
    year = {2021},
    url = {https://doi.org/10.32614/RJ-2021-053},
    doi = {10.32614/RJ-2021-053},
    volume = {13},
    issue = {1},
    pages = {570-580},
  }
```

## Contributing

Big thank you to `@jeffreybears` for the hex sticker!

Please note that the {gtsummary} project is released with a [Contributor Code of Conduct](https://www.danieldsjoberg.com/gtsummary/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. Thank you to all contributors!  

Owner

  • Name: Daniel Sjoberg
  • Login: ddsjoberg
  • Kind: user
  • Location: San Francisco Bay Area
  • Company: Genentech

Senior Principal Data Scientist @Genentech; previously @sloan_kettering; Golden Girls Superfan

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 2,054
  • Total Committers: 45
  • Avg Commits per committer: 45.644
  • Development Distribution Score (DDS): 0.318
Past Year
  • Commits: 459
  • Committers: 13
  • Avg Commits per committer: 35.308
  • Development Distribution Score (DDS): 0.364
Top Committers
Name Email Commits
Daniel Sjoberg d****g@g****m 1,401
Daniel Sjoberg s****d@m****g 324
Emily de la Rua e****a@c****m 147
Joseph Larmarange j****h@l****t 50
Karissa k****g@g****m 22
Sjoberg S****D@m****g 20
Lavery l****j@m****g 15
Margaret Hannum m****m@g****m 8
Abinaya Yogasekaram 7****m 6
Emily Vertosick v****e@m****g 6
Curry c****1@m****g 5
Emily C. Zabor e****r@g****m 5
jflynn264 j****4@g****m 4
Shannon Pileggi p****s@m****g 3
Jenny Bryan j****n@g****m 3
Alan Haynes a****s 2
Davide Garolini d****i@r****m 2
Zelos Zhu z****u@a****m 2
oranwutang 6****g 2
slobaugh 5****h 2
Daniel D. Sjoberg d****g@g****m 1
Corrado Lanera c****a@g****m 1
ltin1214 4****4 1
jwoolfolk 1****k 1
emilyvertosick 4****k 1
bx259 5****9 1
Victoria Catharine 1****e 1
Stephanie Zimmer s****r@g****m 1
Mervin Fansler m****r@g****m 1
Meghan - The Tidy Trekker 6****a 1
and 15 more...
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 518
  • Total pull requests: 617
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 6 days
  • Total issue authors: 215
  • Total pull request authors: 22
  • Average comments per issue: 1.66
  • Average comments per pull request: 0.49
  • Merged pull requests: 545
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 206
  • Pull requests: 234
  • Average time to close issues: 9 days
  • Average time to close pull requests: 4 days
  • Issue authors: 91
  • Pull request authors: 15
  • Average comments per issue: 1.02
  • Average comments per pull request: 0.67
  • Merged pull requests: 205
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • ddsjoberg (226)
  • edelarua (10)
  • larmarange (9)
  • CharlyMarie (5)
  • NourEdinDarwish (5)
  • spiralparagon (4)
  • dchiu911 (4)
  • Melkiades (4)
  • zhangkaicr (4)
  • szimmer (3)
  • DesiQuintans (3)
  • aghaynes (3)
  • ltj-github (3)
  • cmboeker (3)
  • ayogasekaram (3)
Pull Request Authors
  • ddsjoberg (489)
  • edelarua (51)
  • ayogasekaram (18)
  • Melkiades (11)
  • zdz2101 (11)
  • larmarange (8)
  • aghaynes (3)
  • 10b14224cc (2)
  • Meghansaha (2)
  • gungorMetehan (2)
  • ngsanogo (2)
  • jwoolfolk (2)
  • JoanneF1229 (2)
  • MauKappel (2)
  • krlmlr (2)
Top Labels
Issue Labels
v2.0 (49) good for beginners :heart: (14) v2.0 :crossed_fingers::crossed_fingers: (6) bug :bug: (5) help wanted (4) enhancement :star2: (3) waiting (2) High Priority (2) Low Priority (2) documentation :bookmark_tabs: (1) stale issue (1) hackathon (1)
Pull Request Labels
v2.0 :crossed_fingers::crossed_fingers: (4) bug :bug: (4) enhancement :star2: (2) v2.0 (1)

Packages

  • Total packages: 3
  • Total downloads:
    • cran 31,353 last-month
  • Total docker downloads: 46,672
  • Total dependent packages: 18
    (may contain duplicates)
  • Total dependent repositories: 44
    (may contain duplicates)
  • Total versions: 95
  • Total maintainers: 1
cran.r-project.org: gtsummary

Presentation-Ready Data Summary and Analytic Result Tables

  • Versions: 38
  • Dependent Packages: 17
  • Dependent Repositories: 42
  • Downloads: 31,353 Last month
  • Docker Downloads: 46,672
Rankings
Stargazers count: 0.3%
Forks count: 0.7%
Downloads: 1.8%
Dependent repos count: 3.9%
Dependent packages count: 4.3%
Average: 5.3%
Docker downloads count: 20.6%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/ddsjoberg/gtsummary
  • Versions: 41
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.7%
Dependent repos count: 5.9%
Last synced: 6 months ago
conda-forge.org: r-gtsummary
  • Versions: 16
  • Dependent Packages: 1
  • Dependent Repositories: 2
Rankings
Stargazers count: 14.2%
Forks count: 18.7%
Dependent repos count: 20.2%
Average: 20.5%
Dependent packages count: 29.0%
Last synced: 6 months ago

Dependencies

.github/workflows/R-CMD-check-historic-R-versions.yaml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/upload-artifact main composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • actions/upload-artifact main composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/close.yaml actions
  • actions/stale v3 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/pr-fetch v2 composite
  • r-lib/actions/pr-push v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 3.4 depends
  • broom >= 1.0.1 imports
  • broom.helpers >= 1.11.0 imports
  • cli >= 3.1.1 imports
  • dplyr >= 1.0.7 imports
  • forcats >= 0.5.1 imports
  • glue >= 1.6.0 imports
  • gt >= 0.8.0 imports
  • knitr >= 1.37 imports
  • lifecycle >= 1.0.1 imports
  • purrr >= 0.3.4 imports
  • rlang >= 1.0.3 imports
  • stringr >= 1.4.0 imports
  • tibble >= 3.1.6 imports
  • tidyr >= 1.1.4 imports
  • vctrs >= 0.5.1 imports
  • Hmisc * suggests
  • aod >= 1.3.1 suggests
  • broom.mixed >= 0.2.9 suggests
  • car >= 3.0 suggests
  • cmprsk * suggests
  • covr * suggests
  • effectsize >= 0.6.0 suggests
  • emmeans >= 1.7.3 suggests
  • flextable >= 0.8.1 suggests
  • geepack * suggests
  • ggstats >= 0.2.1 suggests
  • huxtable >= 5.4.0 suggests
  • insight >= 0.15.0 suggests
  • kableExtra >= 1.3.4 suggests
  • lme4 * suggests
  • mgcv * suggests
  • mice >= 3.10.0 suggests
  • nnet * suggests
  • officer * suggests
  • openxlsx * suggests
  • parameters >= 0.19.0 suggests
  • parsnip >= 0.1.7 suggests
  • rmarkdown * suggests
  • sandwich >= 3.0.1 suggests
  • scales * suggests
  • smd >= 0.6.6 suggests
  • spelling >= 2.2 suggests
  • survey * suggests
  • survival >= 3.2 suggests
  • testthat >= 3.0.4 suggests
  • tidycmprsk >= 0.1.2 suggests
  • workflows >= 0.2.4 suggests