024: NET changes

gtExtras
Published

March 24, 2023

Load data

Code
 # function to grab NET data
net_ranks <- function(url) {
  
  net_page <- read_html(url)
  
  net_rk <- net_page %>%
    html_nodes("table") %>%
    .[1] %>%
    html_table(fill = TRUE)
  
  net_table <- as.data.frame(net_rk)  

  net_table <- net_table %>%   
    mutate(prev_day_result = net_table[,3]) %>% 
    mutate(date = gsub("[^0-9.-]", "", colnames(net_table[3]))) %>% 
    mutate(date = str_sub(date, end = -2)) %>%
    mutate(record = str_split(WL, "-", simplify = T),
           wins = record[,1],
           losses = record[,2],
           conf_record = str_split(Conf..Record, "-", simplify = T),
           wins_conf = conf_record[,1],
           losses_conf = conf_record[,2],
           non_conf_record = str_split(Non.Conference.Record, "-", simplify = T),
           wins_non_conf = non_conf_record[,1],
           losses_non_conf = non_conf_record[,2],
           first_q = str_split(Quadrant.1, "-", simplify = T),
           q1_win = first_q[,1],
           q1_loss = first_q[,2],
           second_q = str_split(Quadrant.2, "-", simplify = T),
           q2_win = second_q[,1],
           q2_loss = second_q[,2],
           third_q = str_split(Quadrant.3, "-", simplify = T),
           q3_win = third_q[,1],
           q3_loss = third_q[,2],
           fourth_q = str_split(Quadrant.4, "-", simplify = T),
           q4_win = fourth_q[,1],
           q4_loss = fourth_q[,2],
    ) %>% 
    rename(team = Team, conf = Conference, net = NET, prev_net = Prev.NET, 
           sos = NET.SOS, non_conf_sos = NET.NonConf.SOS) %>% 
    select(team, conf, net, prev_net, prev_day_result, sos, non_conf_sos, wins, 
           losses, wins_non_conf, losses_non_conf, q1_win, q1_loss, 
           q2_win, q2_loss, q3_win, q3_loss, q4_win, q4_loss, date) %>% 
    mutate_at(vars(-team, -conf, -date, -prev_day_resu), as.numeric)

}

# function to loop through and grab all data
# net_nums <- function(id) {
# net_ranks(url = id)
# }

# ids <- read_csv("ids.csv) 
# ids <- ids$urls 

# function to get ACC games 
# all_net_rks <- lapply(ids, net_nums)

# load csv of scraped ids

# full_net <- as.data.frame(do.call(rbind, all_net_rks)) 

# load just the acc teams 
lun_acc <- read_csv("acc_teams.csv")

Create GT Table

Code
table <- lun_acc %>%
  select(team, opponent, prev_day_result, net, prev_net, diff) %>%
  gt() %>%
  cols_label(
    # rename columns
    team = "Team",
    opponent = "Opponent",
    prev_day_result = "Result",
    net = "After",
    prev_net = "Before",
    diff = "+/-"
  ) %>%
  data_color(columns = c(diff),
             colors = scales::col_numeric(
               c(
                 "#ca5800",
                 "#cfe8f3",
                 "#73bfe2",
                 "#0a4c6a",
                 "#fff2cf",
                 "#fdd870",
                 "#fdbf11"
               ),
               domain = NULL
             )) %>%
  tab_spanner(label = "NET Change",
              columns = c(net, prev_net, diff)) %>%
  gt_theme_538() %>%
  tab_header(title = "ACC teams that went down in NET ranking after a win") %>%
  tab_source_note(source_note = "@dadgumboxscores | March 30, 2023 | data via NCAA") %>%
  tab_options (
    source_notes.font.size = px(10),
    row.striping.background_color = '#ffffed',
    table.font.size = px(10),
    column_labels.text_transform = 'capitalize'
  )

gtsave_extra(table,
             "lun_acc.png",
             vwidth = 650,
             vheight = 650)

table
ACC teams that went down in NET ranking after a win
Team Opponent Result NET Change
After Before +/-
NC State Louisville W, 76-64 56 42 -14
Wake Forest Georgia Tech W, 71-70 73 67 -6
Syracuse Louisville W, 70-69 143 137 -6
NC State Notre Dame W, 85-82 41 36 -5
Clemson Louisville W, 83-70 59 54 -5
Wake Forest Notre Dame W, 66-58 84 80 -4
NC State Georgia Tech W, 72-64 42 38 -4
North Carolina Boston College W, 72-64 37 33 -4
Pittsburgh Georgia Tech W, 76-68 53 50 -3
Duke Louisville W, 79-62 29 26 -3
Virginia Louisville W, 61-58 16 13 -3
Clemson Florida State W, 82-81 59 56 -3
Duke Miami W, 68-66 29 26 -3
Virginia Syracuse W, 73-66 21 18 -3
Virginia Tech Notre Dame W, 67-64 70 68 -2
Miami Louisville W, 93-85 32 30 -2
Duke North Carolina W, 63-57 25 23 -2
Duke North Carolina W, 62-57 24 23 -1
Virginia Clemson W, 64-57 29 28 -1
Miami Wake Forest W, 96-87 31 30 -1
Duke Notre Dame W, 68-64 33 32 -1
Virginia Tech Notre Dame W, 93-87 56 55 -1
Florida St. Louisville W, 81-78 209 208 -1
Notre Dame Louisville W, 76-62 184 183 -1
@dadgumboxscores | March 30, 2023 | data via NCAA