Skip to content

Commit

Permalink
updates (ddsjoberg#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg authored Apr 23, 2023
1 parent e24761c commit 8751d51
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 266 deletions.
5 changes: 3 additions & 2 deletions R/tbl_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@
#' tbl_regression(exponentiate = TRUE)
#'
#' # Example 3 ----------------------------------
#' # round all estimates to 3 decimal places
#' suppressMessages(library(lme4))
#' tbl_regression_ex3 <-
#' glmer(am ~ hp + (1 | gear), mtcars, family = binomial) %>%
#' tbl_regression(exponentiate = TRUE)
#' lmer(hp ~ am + (1 | gear), data = mtcars) %>%
#' tbl_regression(estimate_fun = function(x) style_number(x, digits = 3))
#' }
#' @section Example Output:
#' \if{html}{Example 1}
Expand Down
60 changes: 18 additions & 42 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,30 @@ Example basic table:

```{r table1, include = TRUE}
library(gtsummary)
# make dataset with a few variables to summarize
trial2 <- trial %>% select(age, grade, response, trt)
# summarize the data with our package
table1 <- tbl_summary(trial2)
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 = file.path(tempdir(), "temp.png"))
gt::gtsave(as_gt(table1), file = "man/figures/README-tbl_summary_print_simple-1.png")
```

```{r out.width = "30%", echo = FALSE}
# Have to do this workaround since the README needs markdown format for GitHub page but a different format for the website.
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
table1
} else {
knitr::include_graphics("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(
trial2,
trial,
include = c(age, grade, response),
by = trt, # split table by group
missing = "no" # don't list missing data separately
) %>%
Expand All @@ -105,16 +102,12 @@ table2 <-
```

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


```{r out.width = "60%", echo = FALSE}
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
table2
} else {
knitr::include_graphics("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
Expand All @@ -128,16 +121,12 @@ t1 <- tbl_regression(mod1, exponentiate = TRUE)
```

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


```{r out.width = "40%", echo = FALSE}
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
t1
} else {
knitr::include_graphics("man/figures/README-tbl_regression_printa-1.png")
}
knitr::include_graphics("man/figures/README-tbl_regression_printa-1.png")
```

### Side-by-side Regression Models
Expand All @@ -161,16 +150,12 @@ tbl_merge_ex1 <-
```

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


```{r out.width = "60%", echo = FALSE}
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
t3
} else {
knitr::include_graphics("man/figures/README-tbl_merge_ex1-1.png")
}
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)**.
Expand All @@ -191,20 +176,12 @@ knitr::include_graphics("man/figures/gt_output_formats.PNG")

## Save Individual Tables

{gtsummary} tables can also be saved directly to file as an image, RTF, LaTeX, and Word file.
{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 .html .tex .ltx .rtf
```

For a Word file, use

```r
tbl %>%
as_flex_table() %>%
flextable::save_as_docx()
gt::gtsave(filename = ".") # use extensions .png, .html, .docx, .rtf, .tex, .ltx
```

## Additional Resources
Expand Down Expand Up @@ -246,5 +223,4 @@ A BibTeX entry for LaTeX users is
Big thank you to [&#x0040;jeffreybears](https://www.etsy.com/shop/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!
`r usethis::use_tidy_thanks("ddsjoberg/gtsummary", from = "2018-01-01") %>% {glue::glue("[&#x0040;{.}](https://github.com/{.})")} %>% glue::glue_collapse(sep = ", ", last = ", and ")`

Loading

0 comments on commit 8751d51

Please sign in to comment.