unc_data <- readr::read_csv("unc_data.csv")
# Create a complete 60-minute tibble
unc_data_60 <- tibble::tibble(
minute = 1:60
) |>
dplyr::left_join(unc_data, by = "minute") |>
dplyr::mutate(
TCU = dplyr::if_else(minute == 60, 0, TCU),
UCF = dplyr::if_else(minute == 60, 0, UCF),
Clemson = dplyr::if_else(minute == 60, 0, Clemson),
Cal = dplyr::if_else(minute == 60, 0, Cal),
Virginia = dplyr::if_else(minute == 60, 0, Virginia)
) |>
dplyr::select(minute, TCU, UCF, Clemson, Cal, Virginia)
# Prepare data for tile plot
tile_data <- unc_data_60 |>
tidyr::pivot_longer(
cols = c(TCU, UCF, Clemson, Cal, Virginia),
names_to = "team",
values_to = "status"
) |>
dplyr::mutate(
status_label = dplyr::case_when(
status == 1 ~ "Leading",
status == 0 ~ "Trailing",
is.na(status) ~ "Tied"
),
status_label = factor(status_label, levels = c("Leading", "Tied", "Trailing")),
team = factor(
team,
levels = c("Virginia", "Cal", "Clemson", "UCF", "TCU"),
labels = c("Virginia\nL, 17-16 (OT)", "Cal\nL, 21-18", "Clemson\nL, 38-10", "UCF\nL, 34-9", "TCU\nL, 48-14")
)
)
title_unc <- "<img src='https://a.espncdn.com/combiner/i?img=/redesign/assets/img/icons/ESPN-icon-football-college.png' width='15'/> North Carolina <img src='https://a.espncdn.com/combiner/i?img=/redesign/assets/img/icons/ESPN-icon-football-college.png' width='15'/><br> against P4 Opponents"
unc_tileplot <- ggplot2::ggplot(tile_data, ggplot2::aes(x = minute, y = team, fill = status_label)) +
ggplot2::geom_tile(color = "white", linewidth = 0.5, height = 0.5) +
ggplot2::scale_fill_manual(
values = c("Leading" = "#56a0d3", "Tied" = "#e1e1e1", "Trailing" = "#e75480"),
name = ""
) +
ggplot2::scale_x_continuous(
breaks = c(0, 15, 30, 45, 60),
expand = c(0, 0)
) +
ggplot2::coord_fixed(ratio = 10) +
ggplot2::labs(
title = title_unc,
subtitle = "Each tile represents one minute of game time.<br>Carolina's last lead was after <br>the opening drive against TCU.",
x = "Minutes",
y = "",
caption = "Virginia won in overtime (untimed)<br> it's denoted here as the final minute.<br><br>**Data via espn.com, theme from {flexoki} package <br> Viz by Chris at Bless your Chart**"
) +
flexoki::theme_flexoki_light() +
ggplot2::theme(
plot.title = ggtext::element_markdown(hjust = 0.5, size = 16),
plot.subtitle = ggtext::element_markdown(hjust = 0.5, size = 10, lineheight = 1.3),
legend.position = "top",
axis.text.y = ggplot2::element_text(size = 10, face = "bold"),
axis.text.x = ggplot2::element_text(size = 10),
panel.grid = ggplot2::element_blank(),
plot.caption = ggtext::element_markdown(size = 9, margin = ggplot2::margin(t = 10)),
plot.margin = ggplot2::margin(20, 20, 20, 20)
)
unc_tileplot