# function to add headers
add_team_header <- function(team_name, img_url) {
gtExtras::img_header(
label = "",
img_url = img_url,
height = 30,
font_size = 14,
palette = c("white")
)
}
# acc headers
team_headers <- c(
"Clemson", "Florida State", "Louisville", "North Carolina", "NC State",
"Miami", "Pittsburgh", "Duke", "Wake Forest", "Syracuse", "Boston College",
"Georgia Tech", "Virginia Tech", "Virginia"
)
# cfbplotR urls from https://github.com/Kazink36/cfbplotR/blob/main/data-raw/logo_ref_2.csv
team_img_urls <- c(
"http://a.espncdn.com/i/teamlogos/ncaa/500/228.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/52.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/97.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/153.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/152.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/2390.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/221.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/150.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/154.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/183.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/103.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/59.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/259.png",
"http://a.espncdn.com/i/teamlogos/ncaa/500/258.png"
)
# add teams headers
team_headers_with_images <- purrr::map2(team_headers, team_img_urls, add_team_header) |>
purrr::set_names(team_headers)
# Create the formatted table
conf_table <- conf_sched |>
gt::gt() |>
gt::tab_header(
title = "ACC Football 2023 Conference Schedule",
subtitle = "Home conference games in green."
) |>
gt::tab_source_note(
source_note = "Bless your chart | data via cfbfastR + cfbplotR"
) |>
gtExtras::gt_theme_538() |>
gt::cols_label(week = "Week", !!!team_headers_with_images) |>
cfbplotR::gt_fmt_cfb_logo(columns = team_headers) |>
gt::text_transform(
locations = gt::cells_body(columns = "Clemson", rows = week %in% c("3", "7", "10", "13")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Florida State", rows = week %in% c("1", "5", "12", "13")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Louisville", rows = week %in% c("3", "6", "8", "13")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "North Carolina", rows = week %in% c("1", "3", "5", "10")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = team_headers, rows = week %in% c("2")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "NC State", rows = week %in% c("1", "3", "6", "8")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Miami", rows = week %in% c("1", "3", "4", "5")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Pittsburgh", rows = week %in% c("1", "3", "6", "9")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Duke", rows = week %in% c("3", "4", "5", "6")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Wake Forest", rows = week %in% c("1", "3", "5", "12")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Syracuse", rows = week %in% c("1", "3", "4", "8")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Boston College", rows = week %in% c("1", "6", "7", "9")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Georgia Tech", rows = week %in% c("3", "5", "7", "13")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Virginia Tech", rows = week %in% c("1", "3", "4", "8")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::text_transform(
locations = gt::cells_body(columns = "Virginia", rows = week %in% c("1", "3", "6", "7")),
fn = function(x) {
gt::web_image(
url = "",
height = 30
)
}
) |>
gt::tab_style(style = list(gt::cell_borders(
sides = c("left"),
color = "#c1c1c1",
weight = gt::px(2)
)),
locations = list(gt::cells_body(columns = everything()))) |>
gt::tab_style(style = list(gt::cell_borders(
sides = c("right"),
color = "#c1c1c1",
weight = gt::px(2)
)),
locations = list(gt::cells_body(columns = c("Virginia")))) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Clemson",
rows = week %in% c("4", "6", "11", "12"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Florida State",
rows = week %in% c("6", "7", "8", "11"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Louisville",
rows = week %in% c("4", "9", "10", "11"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "North Carolina",
rows = week %in% c("6", "7", "8", "11"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "NC State",
rows = week %in% c("5", "9", "10", "13"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Miami",
rows = week %in% c("6", "8", "9", "12"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Pittsburgh",
rows = week %in% c("4", "7", "10", "12"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Duke",
rows = week %in% c("1", "7", "10", "13"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Wake Forest",
rows = week %in% c("4", "8", "9", "11"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Syracuse",
rows = week %in% c("5", "10", "11", "13"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Boston College",
rows = week %in% c("3", "5", "11", "12"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Georgia Tech",
rows = week %in% c("1", "8", "9", "12"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Virginia Tech",
rows = week %in% c("5", "7", "9", "12"
)
)
) |>
gt::tab_style(
style = list(
gt::cell_fill(color = "lightgreen")
),
locations = gt::cells_body(
columns = "Virginia",
rows = week %in% c("4", "10", "12", "13"
)
)
) -> conf_table
gtExtras::gtsave_extra(conf_table,
"conf_table.png",
vwidth = 850,
vheight = 1050)
conf_table