085: NCAAT Game Scores

cbbplotR
gt
nanoplots
Published

March 19, 2024

Load data

Code
library(cbbplotR)

# load seeds 
seeds <- readr::read_csv("https://gist.githubusercontent.com/gallochris/86fc2a21dd4b30e3dd9ea79516594f05/raw/1e2dfa7eae2d196f5dee9ecf5fe95e5f76ba827d/ncaat_seeds.csv") |> 
  dplyr::select(seed = Seed, team = Team, region = Region)
        
# only nccat teams 
ncaat_teams <- seeds |> 
  dplyr::pull(team)

cbbdata::cbd_torvik_game_stats(year = 2024) |> 
  dplyr::filter(team %in% ncaat_teams) |> 
  dplyr::group_by(team) |> 
  dplyr::summarise(
    record = paste0(sum(result == "W"), "-", sum(result == "L")),
    avg = mean(game_score),
    avg_last_10 = mean(head(game_score, 10)),
    sum_data = list(rev(game_score)),
    max_game = max(game_score),
    max_result = result[which.max(game_score)],
    max_opp = opp[which.max(game_score)],
    max_pts_scored =  pts_scored[which.max(game_score)],
    max_pts_allowed =  pts_allowed[which.max(game_score)],
    min_game = min(game_score),
    min_result = result[which.min(game_score)],
    min_opp = opp[which.min(game_score)],
    min_pts_scored =  pts_scored[which.min(game_score)],
    min_pts_allowed =  pts_allowed[which.min(game_score)],
  ) |> 
  dplyr::mutate(
    max_score = paste0(max_result, ", ", 
                       max_opp, " ",
                       max_pts_scored, "-",
                       max_pts_allowed),
    min_score = paste0(min_result, ", ", 
                       min_opp, " ",
                       min_pts_scored, "-",
                       min_pts_allowed),
  ) |> 
  dplyr::select(team, record, avg, avg_last_10, sum_data, max_score, max_game, min_score, min_game,) |> 
  dplyr::arrange(-avg) -> gscores
API Key set!
Code
# join the data with seeds 
ncaat_gscores <- gscores |> 
  dplyr::left_join(seeds, by = "team") |> 
  dplyr::relocate(seed, .before = team) |> 
  dplyr::relocate(region, .after = team)

Game Score Function by Region

Code
  region_tbl <- function(region) {

  # Set the title of the plot
  table_title <-
    paste0(region, " Region: Range of Game Scores")
  
  ncaat_gscores |>
    dplyr::filter(region == {
      {
        region
      }
    }) |>
    dplyr::arrange(seed) |> 
    cbbplotR::gt_cbb_teams(team, team) |> 
    gt::gt() |>
    gt::fmt_markdown(columns = c(team)) |>
    gt::cols_hide(columns = c(region)) |> 
    gt::cols_label(
      seed = "Seed",
      team = "",
      record = "W-L",
      avg = "Avg",
      avg_last_10 = "Last 10",
      sum_data = "Change",
      max_score = "Best Performance",
      max_game = "",
      min_score = "Worst Performance",
      min_game = ""
    ) |>
    gt::fmt_number(columns = c(avg, avg_last_10), decimals = 1) |> 
     gt::cols_nanoplot(
        columns = sum_data,
        reference_line = "mean",
        autohide = TRUE,
        new_col_label = "Season Performance",
        options = gt::nanoplot_options(
            data_area_fill_color = "#eabfff",
            reference_line_color = "#333333",
            show_data_area = TRUE,
            show_data_points = FALSE
        )
    ) |> 
    cbbplotR::gt_theme_athletic() |>
    gt::cols_align(align = "left", columns = c(team, max_score, min_score)) |>
    gtExtras::gt_hulk_col_numeric(columns = c(avg, avg_last_10,
                                              max_game, min_game),
                                  domain = c(0, 100)) |>
    gtExtras::gt_add_divider(columns = c(record, avg_last_10, max_game), sides = "right", color = "black") |> 
       gtExtras::gt_add_divider(columns = c(avg), sides = "right",
                                style = "dotted") |> 
    gt::tab_header(title = table_title,
                   subtitle = gt::html("Game Score is from 
                        barttorvik.com and calculated on a per game basis. An average score is 50. <br>Shows the season average, average of the last 10, the high/low with results, and the season performance to date.")) |>
    gt::tab_source_note(source_note = gt::html("<hr><br><b>Viz by Fifth Factor + Bless your chart | data from Bart Torvik, cbbdata, and cbbplotR | March 19, 2024</b>")) |> 
    gt::tab_style(
      locations = gt::cells_title(groups = "subtitle"),
      style = gt::cell_text(
        size = "medium"
      )
    ) |> 
        gt::tab_style(
      locations = gt::cells_source_notes(),
      style = gt::cell_text(
        size = "small"
      )
    ) |> 
      gt::tab_style(
      style = gt::cell_borders(sides = "top", color = 'black', weight = gt::px(1.5), style = 'solid'),
      locations = gt::cells_body(
        rows = gt::everything()
      )
    ) -> ncaat_region_table

  ncaat_region_table
}

Run and save the function

Code
region_tbl(region = "West") -> west 

  gtExtras::gtsave_extra(west,
                       filename = "nccat_gscore_tbl-w.png",
                       vheight = 725,
                       vwidth = 1175)

  region_tbl(region = "East") -> east

  gtExtras::gtsave_extra(east,
                       filename = "nccat_gscore_tbl-e.png",
                       vheight = 725,
                       vwidth = 1175)
  
  region_tbl(region = "Midwest") -> midwest 

  gtExtras::gtsave_extra(midwest,
                       filename = "nccat_gscore_tbl-mw.png",
                       vheight = 725,
                       vwidth = 1175)
  
  region_tbl(region = "South") -> south 

  gtExtras::gtsave_extra(south,
                       filename = "nccat_gscore_tbl-s.png",
                       vheight = 725,
                       vwidth = 1175)
  
  region_tbl(region = "West")
West Region: Range of Game Scores
Game Score is from barttorvik.com and calculated on a per game basis. An average score is 50.
Shows the season average, average of the last 10, the high/low with results, and the season performance to date.
Seed W-L Avg Last 10 Best Performance Worst Performance Season Performance
1

North Carolina

27-7 88.3 87.2 W, Syracuse 103-67 99.5 L, North Carolina St. 76-84 56.6
88.3 99.5 56.6 72.4 78.9 96.9 93.6 86.5 92.1 98.7 77.1 88.7 77.4 97.4 96.3 97.3 96.4 96.9 99.5 88.2 92.1 97.6 90.9 68.8 97.5 57.9 90.4 62.4 95.2 99.0 82.9 88.4 99.3 98.6 98.1 91.3 56.6
2

Arizona

25-8 88.7 88.8 W, Colorado 97-50 100.0 L, Stanford 82-100 26.3
88.7 100 26.3 98.8 97.0 94.7 99.2 98.3 97.3 95.9 99.2 90.2 96.0 82.0 98.5 26.3 100 96.7 78.9 96.6 64.0 64.1 97.1 98.5 75.6 94.2 99.1 98.7 75.3 97.8 96.8 98.3 98.9 50.8 98.9 73.7
3

Baylor

22-10 86.9 86.8 W, Northwestern St. 91-40 99.5 L, Michigan St. 64-88 12.9
86.9 99.5 12.9 96.6 74.9 97.8 94.5 94.2 95.5 99.5 98.0 12.9 83.3 98.3 93.9 82.4 93.0 85.4 82.0 90.8 82.1 88.9 97.6 92.1 77.9 98.2 93.4 87.8 89.9 98.2 95.2 88.2 57.7 95.2 64.3
4

Alabama

21-11 86.1 77.8 W, South Alabama 102-46 99.6 L, Tennessee 71-91 55.2
86.1 99.6 55.2 98.5 96.9 99.6 97.1 67.2 92.4 68.7 98.1 95.7 92.5 89.8 98.5 99.3 78.4 98.7 95.0 85.7 55.2 97.0 93.0 81.8 99.5 78.9 93.8 98.4 87.9 58.5 90.1 85.4 63.6 58.8 62.5
5

Saint Mary’s

25-7 81.5 88.1 W, Santa Clara 73-49 99.8 L, Xavier 49-66 15.7
81.5 99.8 15.7 99.3 49.7 43.1 15.7 99.6 60.4 52.5 93.9 93.6 86.4 99.8 95.8 43.5 97.5 80.3 68.6 99.2 99.8 99.0 99.2 57.3 92.8 93.5 97.0 96.2 97.4 82.2 92.7 98.0 33.4 93.0 97.8
6

Clemson

21-11 80.2 78.0 W, Georgia Tech 81-57 98.8 L, Boston College 55-76 10.2
80.2 98.8 10.2 95.4 66.5 62.4 97.0 78.5 96.8 97.3 82.3 95.8 77.6 92.9 98.7 56.0 76.3 49.7 92.0 53.7 91.5 91.6 76.2 61.3 98.4 95.1 90.5 73.9 98.8 93.0 86.9 55.6 94.2 81.5 10.2
7

Dayton

24-7 80.8 75.7 W, Grambling St. 76-46 98.6 L, Duquesne 57-65 50.6
80.8 98.6 50.6 62.8 78.4 74.7 94.5 69.4 67.0 84.1 98.6 90.6 97.3 95.4 55.4 97.2 91.7 97.1 61.2 98.4 92.8 72.7 92.1 77.4 91.1 62.0 88.7 63.7 72.8 95.3 74.8 89.5 68.1 50.6
8

Mississippi St.

21-13 80.5 82.2 W, Tennessee 73-56 99.8 L, Georgia Tech 59-67 20.7
80.5 99.8 20.7 97.7 89.9 91.4 96.5 91.6 84.9 20.7 30.5 99.0 74.5 96.5 90.4 86.9 80.8 97.1 79.7 56.2 89.4 70.3 97.4 73.5 27.5 94.6 98.2 76.3 90.5 97.2 88.0 63.3 59.4 68.5 87.7 99.8 91.6
9

Michigan St.

19-14 84.4 83.0 W, Stony Brook 99-55 99.8 L, Wisconsin 57-70 39.7
84.4 99.8 39.7 58.6 92.0 77.7 98.4 98.8 83.2 96.9 39.7 87.7 99.8 93.3 99.8 93.6 99.6 57.1 88.9 94.1 89.4 92.9 53.9 88.0 93.2 78.6 93.1 96.2 86.1 48.2 85.4 94.2 86.8 64.6 87.4 87.7
10

Nevada

25-7 78.6 86.1 W, Pacific 88-41 99.7 L, New Mexico 55-89 12.1
78.6 99.7 12.1 59.5 96.4 99.7 74.4 93.3 92.4 65.8 17.8 90.5 67.8 93.7 97.7 80.8 84.7 77.5 57.0 56.6 45.6 95.7 12.1 98.8 96.7 91.4 76.4 82.3 97.5 89.9 95.2 76.7 97.5 94.1 60.2
11

New Mexico

25-9 82.5 81.9 W, Nevada 89-55 99.7 L, Air Force 77-78 27.9
82.5 99.7 27.9 95.7 40.4 74.1 71.3 97.7 96.5 93.7 96.9 87.1 95.9 42.7 92.0 69.3 92.8 50.5 95.9 95.7 92.8 89.8 99.7 67.5 95.7 56.4 94.2 66.3 89.0 27.9 72.6 91.6 83.7 97.1 96.7 98.0 96.2
12

Grand Canyon

28-4 72.7 71.8 W, Cal Baptist 68-47 98.3 L, Abilene Christian 73-79 30.9
72.7 98.3 30.9 74.6 86.6 82.9 61.9 45.1 49.0 66.3 92.9 64.1 92.4 91.4 75.5 84.2 42.3 56.6 93.2 91.8 60.9 55.3 76.8 71.8 91.9 92.2 49.3 36.4 63.9 30.9 88.6 93.4 98.3 76.3 88.5
13

College of Charleston

26-7 64.1 75.5 W, Towson 72-56 97.7 W, William & Mary 84-83 27.9
64.1 97.7 27.9 41.3 32.7 58.4 37.3 43.5 68.4 85.8 63.4 71.1 68.1 32.8 88.1 92.3 62.7 60.9 81.7 30.6 56.9 52.1 88.9 47.0 27.9 67.1 73.3 58.8 36.6 92.0 97.7 84.8 89.4 95.0 66.3 61.3
14

Colgate

24-9 50.9 54.0 W, Binghamton 84-49 97.6 L, Iona 65-85 1.7
50.9 97.6 1.70 45.0 85.3 9.30 74.5 65.0 12.4 97.6 47.6 87.2 30.6 1.70 15.0 66.5 29.2 4.10 65.6 20.6 57.7 32.3 87.9 61.7 75.2 66.7 44.9 68.7 71.5 35.1 14.6 78.6 64.5 47.9 18.8 95.0
15

Long Beach St.

19-14 44.4 41.0 W, Hawaii 79-71 86.6 L, Cal St. Northridge 68-84 5.3
44.4 86.6 5.30 18.4 67.8 63.3 76.3 6.50 43.8 36.7 52.4 36.6 81.2 59.9 5.30 24.2 55.3 32.1 28.8 86.6 9.60 58.8 29.5 75.0 23.7 82.3 65.2 50.5 18.2 13.7 17.8 12.2 11.9 78.4 84.2 58.0
16

Howard

16-16 32.7 33.0 L, Cincinnati 81-86 73.6 L, North Carolina Central 54-73 4.6
32.7 73.6 4.60 28.0 68.1 32.5 40.7 23.0 16.3 53.6 73.6 23.5 13.4 30.5 9.00 69.8 38.0 4.60 33.9 21.3 29.5 7.80 29.1 19.3 51.5 58.8 5.90 20.2 14.1 25.7 71.5 10.5 46.8 37.6 38.6
16

Wagner

14-15 30.7 34.2 W, Le Moyne 80-57 82.3 L, Stonehill 61-71 2.5
30.7 82.3 2.50 49.8 6.00 21.1 57.1 4.80 46.6 5.70 4.60 5.70 52.4 2.50 49.6 37.2 62.1 20.6 5.40 33.8 82.3 2.50 33.3 13.9 8.60 29.0 56.8 2.90 7.30 47.3 66.6 75.9


Viz by Fifth Factor + Bless your chart | data from Bart Torvik, cbbdata, and cbbplotR | March 19, 2024