076: Lineup data

gt_table
Published

February 11, 2024

Data

Code
schedule <- bigballR::get_team_schedule(season = "2023-24", team.name = "North Carolina")
================================================================================
Code
schedule |> 
  dplyr::filter(!is.na(Home_Score)) |> 
  dplyr::filter(Home %in% c("Boston College", "Clemson", "Florida St.",
                            "Georgia Tech", "Miami (FL)", "NC State", "Pittsburgh")) |> 
  dplyr::pull(Game_ID) -> home_ids

schedule |> 
  dplyr::filter(!is.na(Home_Score)) |> 
  dplyr::filter(Away %in% c("Clemson", "Florida St.", "Duke", "Louisville", 
                            "Wake Forest", "Syracuse")) |> 
  dplyr::pull(Game_ID) -> away_ids

acc_ids <- c(away_ids, home_ids)

acc_only <- schedule |> 
  dplyr::filter(Game_ID %in% acc_ids)

acc_pbp <-bigballR::get_play_by_play(acc_only$Game_ID)

acc_lineups <- bigballR::get_lineups(play_by_play_data = acc_pbp)

# now cross-check last two lineups 

last_two_pbp <-bigballR::get_play_by_play(acc_only$Game_ID[12:13])

last_two_lineups <- bigballR::get_lineups(play_by_play_data = last_two_pbp)

unc_last_two <- last_two_lineups |> 
  dplyr::filter(Team == "North Carolina") |> 
  dplyr::rowwise() |> 
  dplyr::mutate_at(
    c("P1", "P2", "P3", "P4", "P5"),
    ~ stringr::str_to_title(stringr::str_split(., "\\.", simplify = TRUE)) |>
      stringr::str_c(collapse = " ")
  ) |> 
  dplyr::select(P1:P5, Mins) |> 
  dplyr::mutate(MinPct = Mins / 80) -> no_trimble 

# first 11 games
first_acc_pbp <-bigballR::get_play_by_play(acc_only$Game_ID[1:11])

first_acc_lineups <- bigballR::get_lineups(play_by_play_data = first_acc_pbp)

unc_first_acc <- first_acc_lineups |> 
  dplyr::filter(Team == "North Carolina") |> 
  dplyr::rowwise() |> 
  dplyr::mutate_at(
    c("P1", "P2", "P3", "P4", "P5"),
    ~ stringr::str_to_title(stringr::str_split(., "\\.", simplify = TRUE)) |>
      stringr::str_c(collapse = " ")
  ) |> 
  dplyr::select(P1:P5, Mins) |> 
  dplyr::mutate(MinPct = Mins / (11*40)) -> with_trimble

with_trimble |> 
    dplyr::mutate(dplyr::across(c("P1", "P2", "P3", "P4", "P5"),
                  ~dplyr::case_when(
                      .x == "Rj Davis" ~ "RJ Davis",
                      .x == "Jaelyn Withers" ~ "Jae'Lyn Withers",
                      TRUE ~ .x 
                  )
    )
    ) |> 
    dplyr::arrange(-Mins) |> 
    dplyr::ungroup() |> 
    dplyr::slice(1:5) -> trim_table

# no trimble
no_trimble |> 
  dplyr::mutate(dplyr::across(c("P1", "P2", "P3", "P4", "P5"),
                  ~dplyr::case_when(
                      .x == "Rj Davis" ~ "RJ Davis",
                      .x == "Jaelyn Withers" ~ "Jae'Lyn Withers",
                      TRUE ~ .x 
                  )
    )
    ) |> 
    dplyr::arrange(-Mins) |> 
    dplyr::ungroup() -> no_trim_table

GT Tables

Code
trim_table |> 
    gt::gt() |> 
    gt::cols_label(
        P1 = 1,
        P2 = 2,
        P3 = 3,
        P4 = 4,
        P5 = 5,
        MinPct = "%"
    ) |> 
    gt::fmt_number(columns = c(Mins), decimals = 1) |> 
    gt::fmt_percent(columns = c(MinPct), decimals  = 1) |> 
    gtExtras::gt_highlight_rows(rows = 2:5, columns = c(P5), bold_target_only = TRUE, 
                                target_col = c(P5),
                                fill = "#fffec8") |> 
    gtExtras::gt_theme_538() |> 
    gt::tab_header(title = "North Carolina: Top 5 lineups through first 11 ACC games", 
                   subtitle = "UNC played 60 unique lineups and Seth Trimble was part of four of the five most used linueps.") |> 
    gt::tab_source_note(source_note = "Bless your chart | data via bigballR") -> first_tbl

gtExtras::gtsave_extra(first_tbl,
                       filename = "first_table.png",
                       vheight = 875,
                       vwidth = 850)


no_trim_table |> 
    dplyr::mutate(row_n = dplyr::row_number()) |> 
    dplyr::relocate(row_n, .before = c(P1)) |> 
    gt::gt() |> 
    gt::cols_label(
        row_n = "",
        P1 = 1,
        P2 = 2,
        P3 = 3,
        P4 = 4,
        P5 = 5,
        MinPct = "%"
    ) |> 
    gt::fmt_number(columns = c(Mins), decimals = 1) |> 
    gt::fmt_percent(columns = c(MinPct), decimals  = 1) |> 
    gtExtras::gt_hulk_col_numeric(columns = c(MinPct)) |>  
    gtExtras::gt_theme_dot_matrix() |> 
    gt::tab_header(title = "North Carolina: Lineups last two games in ACC play", 
                   subtitle = "UNC played 22 unique lineups in Seth Trimble's absence.") |> 
    gt::tab_source_note(source_note = "Bless your chart | data via bigballR") |> 
   gt::tab_options (
    source_notes.font.size = gt::px(10),
    row.striping.background_color = '#ffffed',
    table.font.size = gt::px(12),
    column_labels.text_transform = 'capitalize'
  ) -> last_tbl

gtExtras::gtsave_extra(last_tbl,
                       filename = "last_table.png",
                       vheight = 875,
                       vwidth = 850)



first_tbl 
North Carolina: Top 5 lineups through first 11 ACC games
UNC played 60 unique lineups and Seth Trimble was part of four of the five most used linueps.
1 2 3 4 5 Mins %
Armando Bacot Cormac Ryan Elliot Cadeau Harrison Ingram RJ Davis 156.4 35.5%
Armando Bacot Cormac Ryan Harrison Ingram RJ Davis Seth Trimble 38.3 8.7%
Armando Bacot Cormac Ryan Jae'Lyn Withers RJ Davis Seth Trimble 25.8 5.9%
Cormac Ryan Harrison Ingram Jalen Washington RJ Davis Seth Trimble 15.6 3.6%
Armando Bacot Harrison Ingram Jae'Lyn Withers RJ Davis Seth Trimble 14.8 3.4%
Bless your chart | data via bigballR
Code
last_tbl
North Carolina: Lineups last two games in ACC play
UNC played 22 unique lineups in Seth Trimble's absence.
1 2 3 4 5 Mins %
1 Armando Bacot Cormac Ryan Elliot Cadeau Harrison Ingram RJ Davis 29.1 36.4%
2 Armando Bacot Elliot Cadeau Harrison Ingram Paxson Wojcik RJ Davis 8.5 10.7%
3 Armando Bacot Cormac Ryan Harrison Ingram Paxson Wojcik RJ Davis 5.7 7.2%
4 Armando Bacot Harrison Ingram Paxson Wojcik RJ Davis Zayden High 5.0 6.2%
5 Elliot Cadeau Harrison Ingram Jalen Washington Paxson Wojcik RJ Davis 3.4 4.2%
6 Cormac Ryan Harrison Ingram Jalen Washington Paxson Wojcik RJ Davis 3.2 4.1%
7 Armando Bacot Elliot Cadeau Jalen Washington Paxson Wojcik RJ Davis 3.0 3.8%
8 Armando Bacot Cormac Ryan Harrison Ingram Jae'Lyn Withers RJ Davis 2.8 3.5%
9 Armando Bacot Cormac Ryan Jalen Washington Paxson Wojcik RJ Davis 2.7 3.3%
10 Armando Bacot Cormac Ryan Elliot Cadeau Jalen Washington RJ Davis 2.5 3.2%
11 Armando Bacot Cormac Ryan Elliot Cadeau RJ Davis Zayden High 2.3 2.9%
12 Armando Bacot Cormac Ryan Jae'Lyn Withers Paxson Wojcik RJ Davis 1.8 2.2%
13 Armando Bacot Elliot Cadeau Harrison Ingram Jalen Washington RJ Davis 1.6 2.0%
14 Armando Bacot Cormac Ryan Paxson Wojcik RJ Davis Zayden High 1.0 1.3%
15 Armando Bacot Cormac Ryan Elliot Cadeau Harrison Ingram Jae'Lyn Withers 1.0 1.2%
16 Elliot Cadeau Harrison Ingram Jae'Lyn Withers Jalen Washington Paxson Wojcik 1.0 1.2%
17 Armando Bacot Cormac Ryan Elliot Cadeau Harrison Ingram Paxson Wojcik 0.9 1.1%
18 Harrison Ingram Jae'Lyn Withers Jalen Washington Paxson Wojcik RJ Davis 0.9 1.1%
19 Armando Bacot Harrison Ingram Jae'Lyn Withers Paxson Wojcik RJ Davis 0.9 1.1%
20 Armando Bacot Cormac Ryan Harrison Ingram Jalen Washington RJ Davis 0.7 0.8%
21 Elliot Cadeau Harrison Ingram Jalen Washington James Okonkwo RJ Davis 0.7 0.8%
22 Cormac Ryan Harrison Ingram Jae'Lyn Withers Paxson Wojcik RJ Davis 0.3 0.4%
Bless your chart | data via bigballR