Not to be confused with a Game of Thrones
gt
package - a (g)rammar of (t)ablesgt
is an R package for generating formatted tables from dataframes in R with a Grammar of Tables.
If you want to go deeper than this basic guide, check out the gt
site, which has lots of examples!
Raw data comes from: Pro Football Reference & Over the Cap
Per the package website, gt
has the following component parts:
The parts (roughly from top to bottom) are:
- the Table Header (optional; with a title and possibly a subtitle)
- the Stub and the Stub Head (optional; contains row labels, optionally within row groups having row group labels and possibly summary labels when a summary is present)
- the Column Labels (contains column labels, optionally under spanner column labels)
- the Table Body (contains columns and rows of cells)
- the Table Footer (optional; possibly with footnotes and source notes)
As you can see it is fleshing out the idea of formatting or adding various parts of the table in a robust way.
I’ve gone through collecting the data and have put into a non-tidy wide format for Salary Rank, playoff week and appearances, Total appearances, and finally salary from 2014-2019.
library(gt) # for static tables
library(tidyverse) # all the things
library(paletteer) # for all the palettes
playoff_salary <- read_csv("https://raw.githubusercontent.com/jthomasmock/radix_themockup/master/_posts/2020-05-13-qb-salaries-vs-playoff-appearances/playoff_salary.csv")
glimpse(playoff_salary)
Rows: 36
Columns: 7
$ player <chr> "Tom Brady", "Aaron Rodgers", "Russell Wilson", …
$ Wildcard <dbl> 1, 2, 4, 3, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 0, 0, …
$ Division <dbl> 5, 4, 4, 3, 2, 2, 2, 2, 1, 2, 1, 1, 2, 0, 2, 2, …
$ Conference <dbl> 5, 3, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 2, 1, …
$ Superbowl <dbl> 4, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, …
$ Total <dbl> 15, 9, 10, 7, 4, 5, 6, 3, 3, 5, 3, 3, 5, 2, 5, 4…
$ salary <dbl> 100.065, 125.602, 91.114, 127.690, 93.700, 75.26…
A very basic gt
table can be created as so: