Load and Install Packages

if (!requireNamespace('pacman', quietly = TRUE)){
  install.packages('pacman')
}
pacman::p_load(dplyr,tidyr, gt)
pacman::p_load_current_gh("saiemgilani/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/saiemgilani/cfbfastR-data/master/themes/logos.csv")
logos<- logos %>% dplyr::select(-.data$conference)
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/saiemgilani/cfbfastR-data/master/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: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead

## Warning: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead

## Warning: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead

## Warning: `columns = vars(...)` has been deprecated in gt 0.3.0:
## * please use `columns = c(...)` instead
## Warning: `columns = TRUE` has been deprecated in gt 0.3.0:
## * 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

##               category
## 1   completionAttempts
## 2         defensiveTDs
## 3          extraPoints
## 4         fieldGoalPct
## 5           fieldGoals
## 6           firstDowns
## 7        fourthDownEff
## 8          fumblesLost
## 9     fumblesRecovered
## 10       interceptions
## 11     interceptionTDs
## 12   interceptionYards
## 13       kickingPoints
## 14         kickReturns
## 15       kickReturnTDs
## 16     kickReturnYards
## 17     netPassingYards
## 18     passesDeflected
## 19   passesIntercepted
## 20          passingTDs
## 21      possessionTime
## 22         puntReturns
## 23       puntReturnTDs
## 24     puntReturnYards
## 25           qbHurries
## 26     rushingAttempts
## 27          rushingTDs
## 28        rushingYards
## 29               sacks
## 30             tackles
## 31      tacklesForLoss
## 32        thirdDownEff
## 33        totalFumbles
## 34 totalPenaltiesYards
## 35          totalYards
## 36           turnovers
## 37        yardsPerPass
## 38 yardsPerRushAttempt