Last updated: 2019-03-09

Checks: 6 0

Knit directory: gt_examples/

This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190309) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    myproject/

Untracked files:
    Untracked:  code/DeletethisFile.Rmd
    Untracked:  code/vertical_table.R
    Untracked:  data/gt_datasets.svg
    Untracked:  gt_examples.Rproj

Unstaged changes:
    Deleted:    myproject.Rproj

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd 5ec7b0e frm1789 2019-03-09 Change style
html 7b802ff frm1789 2019-03-09 Build site.
html a469093 frm1789 2019-03-09 Build site.
Rmd a7777bb frm1789 2019-03-09 merge origin/master
Rmd 7c4b53c Karl Broman 2019-03-09 Add example with labels spanning multiple columns
html 89f40a6 frm1789 2019-03-09 Build site.
Rmd caba3fa frm1789 2019-03-09 Change style
html 31c611a frm1789 2019-03-09 Build site.
html ccb3d44 frm1789 2019-03-09 Build site.
Rmd a61b98b frm1789 2019-03-09 Change style
html f2e71d4 frm1789 2019-03-09 Build site.
Rmd 74ef3bc frm1789 2019-03-09 Adding examples
html 901ba7d frm1789 2019-03-09 Build site.
Rmd 064a281 frm1789 2019-03-09 Change style
html dfa77be frm1789 2019-03-09 Build site.
Rmd cae060a frm1789 2019-03-09 Change style
html 5b576d8 frm1789 2019-03-09 Build site.
Rmd cf23a3a frm1789 2019-03-09 Change style
html 790ab5f frm1789 2019-03-09 Build site.
Rmd 919499f frm1789 2019-03-09 Change style
html 5172a5d frm1789 2019-03-09 Build site.
Rmd 9bd25af frm1789 2019-03-09 Change style
html f143184 frm1789 2019-03-09 Build site.
html b64b81a frm1789 2019-03-09 Build site.
Rmd 918755d frm1789 2019-03-09 Start my new project
html 40f4a4a frm1789 2019-03-09 Build site.
Rmd cad473d frm1789 2019-03-09 Start workflowr project.

Welcome

This is a small list with 25 visualization using gt Package.

What is this?

GT package is one of the most amazing package to create tables, and we want to show a gallery of examples with full R code to encourage you to use it in your projects.

  • How to start with GT Tables
  • How to customize a basic table
  • Examples about how to use

How to create a good table?

An informal definition could be: “A good table sirve para leer de la forma mas rapida y facil un conjunto de datos numericos”.

25 examples about how to use this amazing package

1. Vertical table

library(gt)
library(tidyverse)
── Attaching packages ──────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.1.0     ✔ purrr   0.2.5
✔ tibble  1.4.2     ✔ dplyr   0.7.8
✔ tidyr   0.8.2     ✔ stringr 1.3.1
✔ readr   1.1.1     ✔ forcats 0.3.0
── Conflicts ─────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(glue)

Attaching package: 'glue'
The following object is masked from 'package:dplyr':

    collapse
# Define the start and end dates for the data range
start_date <- "2010-06-07"
end_date <- "2010-06-14"

# Create a gt table based on preprocessed
# `sp500` table data
sp500 %>%
  dplyr::filter(date >= start_date & date <= end_date) %>%
  dplyr::select(-adj_close) %>%
  dplyr::mutate(date = as.character(date)) %>%
  gt() %>%
  tab_header(
    title = "S&P 500",
    subtitle = glue::glue("{start_date} to {end_date}")
  ) %>%
  fmt_date(
    columns = vars(date),
    date_style = 3
  ) %>%
  fmt_currency(
    columns = vars(open, high, low, close),
    currency = "USD"
  ) %>%
  fmt_number(
    columns = vars(volume),
    scale_by = 1 / 1E9,
    pattern = "{x}B"
  )
S&P 500
2010-06-07 to 2010-06-14
date open high low close volume
Mon, Jun 14, 2010 $1,095.00 $1,105.91 $1,089.03 $1,089.63 4.43B
Fri, Jun 11, 2010 $1,082.65 $1,092.25 $1,077.12 $1,091.60 4.06B
Thu, Jun 10, 2010 $1,058.77 $1,087.85 $1,058.77 $1,086.84 5.14B
Wed, Jun 9, 2010 $1,062.75 $1,077.74 $1,052.25 $1,055.69 5.98B
Tue, Jun 8, 2010 $1,050.81 $1,063.15 $1,042.17 $1,062.00 6.19B
Mon, Jun 7, 2010 $1,065.84 $1,071.36 $1,049.86 $1,050.47 5.47B

2. Horizontal table

3. Table with references

4. Table with spanning columns

This example is Table S2 in Broman et al. (2015) Genetics 192:267-279 doi:https://doi.org/10.1534/genetics.112.142448

# the table's data
tab <- data.frame(n=c(300, 450, 600),
                  all_part_all_crosses = c(4.56, 4.51, 4.49),
                  all_part_min_crosses = c(4.48, 4.47, 4.44),
                  tree_part_all_crosses = c(4.43, 4.36, 4.32),
                  tree_part_min_crosses = c(4.33, 4.33, 4.29))

# create the gt table
gt(tab) %>%
    cols_align("center") %>%
    cols_label(n="total sample size",
               all_part_all_crosses="all crosses",
               all_part_min_crosses="min crosses",
               tree_part_all_crosses="all crosses",
               tree_part_min_crosses="min crosses") %>%
    tab_spanner(label="Tree partitions",
                starts_with("tree")) %>%
    tab_spanner(label="All partitions",
                starts_with("all"))
total sample size All partitions Tree partitions
all crosses min crosses all crosses min crosses
300 4.56 4.48 4.43 4.33
450 4.51 4.47 4.36 4.33
600 4.49 4.44 4.32 4.29


sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2.2  glue_1.3.0      forcats_0.3.0   stringr_1.3.1  
 [5] dplyr_0.7.8     purrr_0.2.5     readr_1.1.1     tidyr_0.8.2    
 [9] tibble_1.4.2    ggplot2_3.1.0   tidyverse_1.2.1 gt_0.1.0       

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5 haven_1.1.2      lattice_0.20-35  colorspace_1.3-2
 [5] htmltools_0.3.6  yaml_2.2.0       rlang_0.3.0.1    pillar_1.3.1    
 [9] withr_2.1.2      modelr_0.1.2     readxl_1.1.0     bindr_0.1.1     
[13] plyr_1.8.4       munsell_0.5.0    commonmark_1.7   gtable_0.2.0    
[17] workflowr_1.2.0  cellranger_1.1.0 rvest_0.3.2      evaluate_0.12   
[21] knitr_1.20       broom_0.5.0      Rcpp_1.0.0       scales_1.0.0    
[25] backports_1.1.2  checkmate_1.8.5  jsonlite_1.6     fs_1.2.6        
[29] hms_0.4.2        digest_0.6.18    stringi_1.2.4    grid_3.5.1      
[33] rprojroot_1.3-2  cli_1.0.1        tools_3.5.1      magrittr_1.5    
[37] sass_0.1.0.9000  lazyeval_0.2.1   crayon_1.3.4     whisker_0.3-2   
[41] pkgconfig_2.0.2  xml2_1.2.0       lubridate_1.7.4  assertthat_0.2.0
[45] rmarkdown_1.10   httr_1.3.1       rstudioapi_0.8   R6_2.3.0        
[49] nlme_3.1-137     git2r_0.23.0     compiler_3.5.1