Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(gt)
library(tidyverse)
library(nflseedR)
library(espnscrapeR)
# nflseedR code
sim <- simulate_nfl(...)
sim$overall
# # A tibble: 32 x 11
# conf division team wins playoff div1 seed1 won_conf won_sb draft1 draft5
# <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 AFC AFC East BUF 11.5 0.956 0.894 0.348 0.258 0.16 0 0
# 2 AFC AFC East MIA 7.92 0.352 0.098 0.01 0.016 0.008 0.004 0.08
# 3 AFC AFC East NE 5.05 0.038 0.004 0 0 0 0.128 0.474
# 4 AFC AFC East NYJ 4.90 0.026 0.004 0 0 0 0.112 0.51
# 5 AFC AFC North BAL 9.57 0.718 0.472 0.066 0.072 0.042 0.004 0.022
# 6 AFC AFC North CIN 6.86 0.192 0.078 0.002 0.006 0.002 0.028 0.2
# 7 AFC AFC North CLE 9.21 0.602 0.394 0.056 0.056 0.032 0.002 0.022
# 8 AFC AFC North PIT 6.63 0.134 0.056 0 0 0 0.028 0.226
# 9 AFC AFC South HOU 9.29 0.662 0.266 0.046 0.058 0.026 0 0.012
# 10 AFC AFC South IND 7.96 0.384 0.106 0.012 0.028 0.014 0.012 0.096
# # … with 22 more rows
gt_nflseedR_overall <- function(data, ...){
data %>%
mutate(division = str_remove(division, "AFC |NFC ")) %>%
select(conf, division, team, wins, playoff, div1:won_sb) %>%
group_by(conf, division) %>%
arrange(desc(won_sb)) %>%
gt() %>%
fmt_number(vars(wins), decimals = 1) %>%
fmt_percent(vars(playoff, div1, seed1, won_conf, won_sb), decimals = 0) %>%
cols_label(
playoff = html("Make<br>Playoffs"),
div1 = html("Win<br>DIV"),
seed1 = html("1st-RD<br>Bye"),
won_conf = html("Win<br>Conf"),
won_sb = html("Win<br>SB")
) %>%
data_color(
columns = vars(playoff, div1, seed1, won_conf, won_sb),
colors = scales::col_numeric(palette = c("white", "#6fc0e7", "#018fd5"), domain = c(0, 1))
) %>%
gt::tab_header(title = md("**2020 NFL Simulations**"), subtitle = md("Team points simulated according to team QBR via `{nflseedR}`")) %>%
tab_source_note(source_note = "Data: nflseedR | Table: @thomas_mock") %>%
espnscrapeR::gt_theme_538()
}
sim$overall %>%
filter(conf == "AFC") %>%
gt_nflseedR_overall()
sim$overall %>%
filter(conf == "NFC") %>%
gt_nflseedR_overall()
@jthomasmock
Copy link
Author

jthomasmock commented Feb 22, 2021

gt-nfc
gt-afc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment