Code
library(cbbplotR)
library(rlang)
<- readr::read_csv("state-unc.csv") state
November 24, 2024
custom_header <- glue::glue(
"<div style='display: flex; justify-content: space-between; align-items: center;'>
<div>
<img src='https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/153.png'
style='height: 45px; width: auto; vertical-align: middle;'>
</div>
<div style='flex-grow:1; margin-left: 30px; margin-right: 30px'>
<span style='display: block; font-weight: bold; text-align: center; font-size: 24px;'>North Carolina against NC State since 2013</span>
<span style='font-size: 14px; font-weight: normal; display: block; text-align: center;'>State is 7-4 against Carolina under Dave Doeren.<br> The Wolfpack have been underdogs in eight of those 11 games.</span>
</div>
<div>
<img src='https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/152.png'
style='height: 45px; width: auto; vertical-align: middle;'>
</div>
</div>
<br>"
)
state_tbl <- state |>
cbbplotR::gt_cbb_teams(Outright, Outright, include_name = FALSE) |>
gt::gt() |>
gtUtils::gt_theme_sofa() |>
gt::fmt_markdown(Outright) |>
gt::fmt_tf(
columns = Cover,
tf_style = "check-mark",
colors = c("#56a0d3", "red"),
na_val = ""
) |>
gtExtras::gt_highlight_rows(
rows = c(1, 2, 4, 5, 8, 9, 10, 11),
columns = c(5),
fill = "#d0e4f3"
) |>
gtExtras::gt_highlight_rows(
rows = c(3, 6, 7),
columns = c(5),
fill = "#ff9a9a"
) |>
gtExtras::gt_highlight_rows(
rows = c(2, 4, 6, 8, 10),
columns = c(4),
fill = "#d0e4f3"
) |>
gtExtras::gt_highlight_rows(
rows = c(1, 3, 5, 7, 9, 11),
columns = c(4),
fill = "#ff9a9a"
) |>
gtExtras::gt_highlight_rows(
rows = c(4, 5, 9, 11),
columns = c(3),
fill = "#d0e4f3"
) |>
gtExtras::gt_highlight_rows(
rows = c(1, 2, 3, 6, 7, 8, 10),
columns = c(3),
fill = "#ff9a9a"
) |>
gt::cols_label(
Outright = "Winner"
) |>
gt::tab_header(title = gt::html(custom_header)) |>
gtUtils::gt_538_caption(
"<hr>Data via TeamRankings.com's BetIQ tool, theme via {gtUtils} and logos from ESPN.",
"<b>Table by Chris at Bless your chart</b>"
) |>
gtUtils::gt_border_bars_bottom(c("#56a0d3", "#89BDE0", "#BBD9ED")) |>
gt::tab_options(table.width = gt::px(650)) |>
gtUtils::gt_border_grid(color = "black",
weight = 1,
include_labels = FALSE)
gtUtils::gt_save_crop(
state_tbl,
file = "state_unc.png",
whitespace = 60,
bg = "#F0EAD6"
)
state_tbl
North Carolina against NC State since 2013
State is 7-4 against Carolina under Dave Doeren.
The Wolfpack have been underdogs in eight of those 11 games. |
|||||
Season1 | Winner1 | Result1 | Location1 | Spread1 | Cover1 |
---|---|---|---|---|---|
2023 | State 39, UNC 20 | Raleigh | UNC -2.5 | ✘ | |
2022 | State 30, UNC 27 (2OT) | Chapel Hill | UNC -6.5 | ✘ | |
2021 | State 34, UNC 30 | Raleigh | UNC +5 | ✔ | |
2020 | UNC 48, State 21 | Chapel Hill | UNC -15 | ✔ | |
2019 | UNC 41, State 10 | Raleigh | UNC -11 | ✔ | |
2018 | State 34, UNC 28 | Chapel Hill | UNC +7 | ✔ | |
2017 | State 33, UNC 21 | Raleigh | UNC +14.5 | ✔ | |
2016 | State 28, UNC 21 | Chapel Hill | UNC -9.5 | ✘ | |
2015 | UNC 45, State 34 | Raleigh | UNC -3.5 | ✔ | |
2014 | State 35, UNC 7 | Chapel Hill | UNC -6.5 | ✘ | |
2013 | UNC 27, State 19 | Raleigh | UNC -5.5 | ✔ | |
Table by Chris at Bless your chart |
|||||
1 Data via TeamRankings.com's BetIQ tool, theme via {gtUtils} and logos from ESPN. |
library(cbbplotR)
library(rlang)
get_unc_records <- function(start_year = 2012,
end_year = 2024) {
years <- start_year:end_year
all_games <- purrr::map_df(years,
~ cfbfastR::cfbd_game_info(year = .x, team = "North Carolina"))
processed_games <- all_games |>
dplyr::mutate(
game_result = dplyr::case_when(
home_team == "North Carolina" & home_points > away_points ~ "W",
home_team == "North Carolina" &
home_points < away_points ~ "L",
home_team != "North Carolina" &
home_points < away_points ~ "W",
home_team != "North Carolina" &
home_points > away_points ~ "L",
TRUE ~ "T" # For ties, if any
)
)
return(processed_games)
}
add_game_numbers <- function(df) {
# First, number the actual games
numbered_games <- df |>
dplyr::group_by(season) |>
dplyr::mutate(game_number = dplyr::row_number()) |>
dplyr::ungroup()
# Create a template with all seasons and 14 game numbers
template <- tidyr::expand_grid(season = unique(df$season), game_number = 1:14)
# Join the actual data with the template
complete_games <- template |>
dplyr::left_join(numbered_games, by = c("season", "game_number"))
return(complete_games)
}
get_unc_records() -> unc_records
unc_records |>
add_game_numbers() -> unc_with_games
# bowl game fixes - this was way too tedius
unc_tbl <- unc_with_games |>
dplyr::select(season, game_number, game_result) |>
dplyr::mutate(
game_result = dplyr::case_when(
game_number == 13 & season == 2013 ~ "W",
game_number == 13 & season == 2014 ~ "L",
game_number == 14 & season == 2015 ~ "L",
game_number == 13 & season == 2016 ~ "L",
game_number == 13 & season == 2019 ~ "W",
game_number == 12 & season == 2020 ~ "L",
game_number == 13 & season == 2021 ~ "L",
game_number == 14 & season == 2022 ~ "L",
game_number == 13 & season == 2023 ~ "L",
TRUE ~ game_result
)
) |>
dplyr::mutate(game_result = dplyr::case_match(game_result, "W" ~ 1, "L" ~ 0, "T" ~ NA)) |>
tidyr::pivot_wider(names_from = game_number, values_from = game_result, ) |>
dplyr::arrange(-season) |> # add w-l records and percentages
dplyr::mutate(
coach = dplyr::case_when(
season %in% c(2019:2024) ~ "Mack Brown 2.0 57.9% | 44-32",
season %in% c(2012:2018) ~ "Larry Fedora 51.1% | 45-43",
)
)
custom_header <- glue::glue(
"<div style='display: flex; justify-content: space-between; align-items: center;'>
<div>
<img src='https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/153.png'
style='height: 55px; width: auto; vertical-align: middle;'>
</div>
<div style='flex-grow:1; margin-left: 30px; margin-right: 30px'>
<span style='display: block; font-weight: bold; text-align: center; font-size: 24px;'>North Carolina's Record by Coach Since 2012</span>
<span style='font-size: 14px; font-weight: normal; display: block; text-align: center;'>Shows the <span style='font-weight: bold; color:#56a0d3'>wins</span> and <span style='font-weight: bold; color:#e75480'>losses</span> by game number of each season.</span>
</div>
<div>
<img src='https://a.espncdn.com/combiner/i?img=/redesign/assets/img/icons/ESPN-icon-football-college.png'
style='height: 45px; width: auto; vertical-align: middle;'>
</div>
</div>
<br>"
)
unc_coach_tbl <- unc_tbl |>
gt::gt(groupname_col = "coach") |>
gtUtils::gt_indicator_boxes(
key_columns = "season",
color_yes = "#56a0d3",
color_no = "#e75480",
color_na = "#e1e1e1"
) |>
gt::cols_label(season = "") |>
gtUtils::gt_theme_sofa() |>
gt::tab_spanner(columns = c(-season), label = "Game Number") |>
gt::tab_header(title = gt::html(custom_header)) |>
gtUtils::gt_538_caption(
"<hr>Data via cfbfastR, theme via {gtUtils}. <br>2024 season data through November 23.
<br>",
"<b>Table by Chris at Bless your chart</b>"
) |>
gtUtils::gt_border_bars_bottom(c("#56a0d3", "#89BDE0", "#BBD9ED")) |>
gt::tab_options(table.width = gt::px(450)) |>
gtUtils::gt_border_grid(color = "black",
weight = 1,
include_labels = FALSE) |>
gt::tab_style(
locations = gt::cells_column_spanners(),
style = gt::cell_text(
font = gt::google_font("Sofia Sans Condensed"),
weight = 650,
transform = "uppercase",
decorate = NULL,
size = gt::px(12)
)
) |>
gt::tab_style(
locations = gt::cells_column_labels(),
style = gt::cell_text(
weight = 'bold',
font = gt::google_font('Sofia Sans Condensed'),
size = gt::px(14),
color = "#acacac"
)
)
gtUtils::gt_save_crop(
unc_coach_tbl,
file = "unc_mack_vs_fedora.png",
whitespace = 40,
bg = "#F0EAD6"
)
unc_coach_tbl
North Carolina's Record by Coach Since 2012
Shows the wins and losses by game number of each season.
|
||||||||||||||
1 | Game Number | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11 | 21 | 31 | 41 | 51 | 61 | 71 | 81 | 91 | 101 | 111 | 121 | 131 | 141 | |
Mack Brown 2.0 57.9% | 44-32 | ||||||||||||||
2024 | ||||||||||||||
2023 | ||||||||||||||
2022 | ||||||||||||||
2021 | ||||||||||||||
2020 | ||||||||||||||
2019 | ||||||||||||||
Larry Fedora 51.1% | 45-43 | ||||||||||||||
2018 | ||||||||||||||
2017 | ||||||||||||||
2016 | ||||||||||||||
2015 | ||||||||||||||
2014 | ||||||||||||||
2013 | ||||||||||||||
2012 | ||||||||||||||
Table by Chris at Bless your chart |
||||||||||||||
1 Data via cfbfastR, theme via {gtUtils}. 2024 season data through November 23. |