Skip to content

Instantly share code, notes, and snippets.

@gallochris
Created September 29, 2021 15:39
Show Gist options
  • Save gallochris/060831408943c7402906da469e7f544a to your computer and use it in GitHub Desktop.
Save gallochris/060831408943c7402906da469e7f544a to your computer and use it in GitHub Desktop.
WynnBet win totals, title odds, and final four odds
library(tidyverse)
library(gt)
# make the data - https://www.wynnbet.com/theplaybook/posts/wynnbet-releases-odds-for-upcoming-men-s-college-basketball-season-01ffk34jmvek
odds <- tibble::tribble(
~team, ~win, ~nt, ~ff,
"Gonzaga", 33.5, 11.1, 33.3,
"UCLA", 31, 7.7, 25.0,
"Michigan", 27, 7.7, 25.0,
"Memphis", 32, 6.3, 20.0,
"Kansas", 28.5, 6.3, 20.0,
"Duke", 28, 6.3, 20.0,
"Villanova", 26.5, 6.3, 20.0,
"Texas", 27.5, 4.8, 16.7,
"Purdue", 26, 4.8, 16.7,
"Kentucky", 26, 4.8, 16.7,
"Baylor", 26, 4.8, 16.7,
"Ohio State", 24.5, 4.8, 16.7,
"Alabama", 24.5, 4.8, 16.7,
"Houston", 27, 3.2, 11.1,
"North Carolina", 23.5, 3.2, 11.1,
"Michigan State", 22.5, 3.2, 11.1,
"Florida State", 22.5, 3.2, 11.1,
"Arkansas", 24.5, 3.2, 11.1,
"Illinois", 25.5, 2.4, 9.1,
"Louisville", 23.5, 2.4, 9.1,
"Maryland", 22.5, 2.4, 9.1,
"Tennessee", 24.5, 2.0, 7.7,
"St. Bonaventure", 29, 2.0, 7.7,
"UConn", 24.5, 2.0, 7.7,
"Texas Tech", 23, 2.0, 7.7,
)
# gt_theme
gt_theme_538 <- function(data,...) {
data %>%
opt_all_caps() %>%
opt_table_font(
font = list(
google_font("Chivo"),
default_fonts()
)
) %>%
tab_style(
style = cell_borders(
sides = "bottom", color = "white", weight = px(2)
),
locations = cells_body(
columns = everything(),
# This is a relatively sneaky way of changing the bottom border
# Regardless of data size
rows = nrow(data$`_data`)
)
) %>%
tab_options(
column_labels.background.color = "white",
table.border.top.width = px(3),
table.border.top.color = "white",
table.border.bottom.color = "white",
table.border.bottom.width = px(3),
column_labels.border.top.width = px(3),
column_labels.border.top.color = "#acacac",
column_labels.border.bottom.width = px(3),
column_labels.border.bottom.color = "#acacac",
data_row.padding = px(3),
source_notes.font.size = 12,
table.font.size = 16,
heading.align = "left",
...
)
}
# gt tables
gt_tbl_odds <- gt(data = odds)
gt_tbl <-
gt_tbl_odds %>%
cols_label(
team = "Team",
win = "Win total",
nt = "Title odds %",
ff = "Final Four odds %"
) %>%
data_color(
columns = c(win),
colors = scales::col_numeric(
palette = c("white", "lightgreen"),
domain = NULL
)
) %>%
tab_style(
style = list(
cell_fill(color = "#daeaf5")
),
locations = cells_body(
rows = 15)
) %>%
tab_header(
title = "2021-22 College Hoops: Win totals, National Title and Final Four odds",
subtitle = "Top-25 teams shows the odds formatted as percentages or probability, win totals include post-season."
) %>%
tab_source_note(
source_note = "Source: WynnBet"
) %>%
gt_theme_538
gt_tbl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment