Skip to contents

Load and Install Packages

if (!requireNamespace('pacman', quietly = TRUE)){
  install.packages('pacman')
}
pacman::p_load(dplyr,tidyr, gt)
pacman::p_load_current_gh("sportsdataverse/cfbfastR")

Settling 2019 LSU and 2013 Florida State offense debates

Get Season Statistics by Team

team_season_stats <- dplyr::bind_rows(
   cfbd_stats_season_team(2019, team = "LSU"),
   cfbd_stats_season_team(2013, team = "Florida State")
)
logos <- read.csv("https://raw.githubusercontent.com/sportsdataverse/cfbfastR-data/main/themes/logos.csv")
logos<- logos %>% dplyr::select(-.data$conference)
## Warning: Use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0.
##  Please use `"conference"` instead of `.data$conference`
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
df_team_season <- team_season_stats %>% 
   dplyr::left_join(logos, by=c("team"="school"))
df_team_season_long <- as.data.frame(t(as.matrix(df_team_season)))
colnames(df_team_season_long) <- df_team_season$team

Get Season Advanced Statistics by Team

df_team_season_adv <- dplyr::bind_rows(
   cfbd_stats_season_advanced(2019, team = "LSU"),
   cfbd_stats_season_advanced(2013, team = "Florida State")
)
df_team_season_adv <- df_team_season_adv %>% 
   dplyr::left_join(logos, by=c("team"="school"))

Get Game Advanced Stats

df_team_game_adv <- dplyr::bind_rows(
   cfbd_stats_game_advanced(2019, team = "LSU"),
   cfbd_stats_game_advanced(2013, team = "Florida State")
)
df_team_game_adv <- df_team_game_adv %>% 
   dplyr::left_join(logos, by=c("team"="school")) 

Get Season Statistics by Player

source("https://raw.githubusercontent.com/sportsdataverse/cfbfastR-data/main/themes/gt_theme_code_SG.R")
passing_df <- dplyr::bind_rows(
   cfbd_stats_season_player(2019, team = "LSU", category = "passing"), 
   cfbd_stats_season_player(2013, team = "Florida State", category = "passing")) %>% 
   dplyr::left_join(logos, by=c("team"="school")) %>%
   dplyr::group_by(team) %>% 
   dplyr::select(logo, 
                 player,
                 passing_completions,
                 passing_att,
                 passing_yds,
                 passing_td,
                 passing_int,
                 passing_ypa) %>% 
   arrange( desc(passing_yds), team)
## Adding missing grouping variables: `team`
passing_df %>% gt() %>% 
  tab_header(title = "Passing Summary") %>%
  cols_label(logo="",
             player = "Player", 
             passing_completions = "C", 
             passing_att = "Att",
             passing_yds = "Yds",
             passing_td = "TDs",
             passing_int = "INTs",
             passing_ypa = "YPA") %>%
  data_color(
    columns = vars(passing_yds),
    colors = scales::col_numeric(
      palette = "RdBu",
      domain = c(-6000,6000)
    )
  ) %>% 
  data_color(
    columns = vars(passing_td),
    colors = scales::col_numeric(
      palette = "RdBu",
      domain = c(-60,60)
    )
  ) %>% 
  data_color(
    columns = vars(passing_td),
    colors = scales::col_numeric(
      palette = "RdBu",
      domain = c(-60,60)
    )
  ) %>% 
  text_transform(
    locations = cells_body(vars(logo)),
    fn = function(logo){
      web_image(url= logo)
  }) %>% 
  tab_source_note(source_note = md("**Table:** @SaiemGilani | **Data:** @CFB_Data with @cfbfastR v1.1.0")) %>% 
  gt_theme_538(table.width = px(550))
## Warning: Since gt v0.9.0, the `colors` argument has been deprecated.
##  Please use the `fn` argument instead.
## This warning is displayed once every 8 hours.
## Warning: Since gt v0.3.0, `columns = vars(...)` has been deprecated.
##  Please use `columns = c(...)` instead.
## Since gt v0.3.0, `columns = vars(...)` has been deprecated.
##  Please use `columns = c(...)` instead.
## Since gt v0.3.0, `columns = vars(...)` has been deprecated.
##  Please use `columns = c(...)` instead.
## Since gt v0.3.0, `columns = vars(...)` has been deprecated.
##  Please use `columns = c(...)` instead.
## Warning: Since gt v0.3.0, `columns = TRUE` has been deprecated.
##  Please use `columns = everything()` instead.
Passing Summary
Player C Att Yds TDs INTs YPA
LSU
Joe Burrow 342 439 4715 48 6 10.7
Myles Brennan 21 37 314 1 1 8.5
Florida State
Jameis Winston 237 349 3820 38 10 10.9
Jake Coker 18 36 250 0 1 6.9
Sean Maguire 13 21 116 2 2 5.5
Table: @SaiemGilani | Data: @CFB_Data with @cfbfastR v1.1.0

College Football Mapping for Stats Categories

## ── Stat categories for CollegeFootballData.com ─────────────── cfbfastR 1.9.5 ──
##  Data updated: 2024-09-10 01:25:58 UTC
## # A tibble: 38 × 1
##    category          
##    <chr>             
##  1 completionAttempts
##  2 defensiveTDs      
##  3 extraPoints       
##  4 fieldGoalPct      
##  5 fieldGoals        
##  6 firstDowns        
##  7 fourthDownEff     
##  8 fumblesLost       
##  9 fumblesRecovered  
## 10 interceptions     
## # ℹ 28 more rows