Created
August 25, 2021 20:50
-
-
Save tejseth/4fcb6a889d522b6f71e1676a03983e0f to your computer and use it in GitHub Desktop.
tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pbp <- nflfastR::load_pbp(2020) | |
pbp_rp <- pbp %>% | |
filter(!is.na(epa)) %>% | |
filter(rush == 1 | pass == 1) | |
teams <- pbp_rp %>% | |
group_by(posteam, pass) %>% | |
summarize(epa = mean(epa)) | |
teams %>% | |
group_by(pass) %>% | |
summarize(league_avg = mean(epa)) | |
browns <- pbp_rp %>% | |
filter(posteam == "CLE") | |
browns_rec <- browns %>% | |
filter(!is.na(receiver_player_name)) %>% | |
group_by(def) %>% | |
summarize(targets = n(), | |
completion_rate = mean(complete_pass), | |
adot = mean(air_yards, na.rm = T), | |
yac = mean(yards_after_catch, na.rm = T), | |
epa = mean(epa)) %>% | |
filter(targets >= 10) | |
pbp_rp <- pbp_rp %>% | |
mutate(yards_past_sticks = air_yards - ydstogo) | |
afc_north <- c("CLE", "PIT", "CIN", "BAL") | |
yps <- pbp_rp %>% | |
filter(!is.na(yards_past_sticks)) %>% | |
filter(down %in% c(2, 3)) %>% | |
group_by(posteam) %>% | |
summarize(avg_yps = mean(yards_past_sticks), | |
yps_rate = 100*mean(yards_past_sticks >= 0), | |
yac = mean(yards_after_catch, na.rm = T)) %>% | |
left_join(teams_colors_logos, by = c("posteam" = "team_abbr")) | |
yps %>% | |
ggplot(aes(x = avg_yps, y = yac)) + | |
geom_smooth(method = "lm", color = "black", size = 2) + | |
geom_hline(yintercept = mean(yps$yac), linetype = "dashed") + | |
geom_vline(xintercept = mean(yps$avg_yps), linetype = "dashed") + | |
geom_image(aes(image = team_logo_espn), asp = 16/9, size = 0.05) + | |
theme_bw() + | |
labs(x = "Average Yards Past Sticks", | |
y = "Average YAC", | |
title = "Each Team's Yards Past Sticks and YAC on 2nd and 3rd Down", | |
subtitle = "2020 only") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment