Created
March 11, 2020 00:39
-
-
Save saiemgilani/52c33ce22c7c2e9272fcde970171ebef to your computer and use it in GitHub Desktop.
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
#Defensive Team Pass/Rush EPA | |
pbp_2019 %>% select(offense_play, defense_play, down, distance, play_type, yards_gained) %>% head() | |
glimpse(pbp_2019) | |
levels(factor(pbp_2019$play_type)) | |
pbp_2019 %>% count(play_type, sort = TRUE) | |
plays <- pbp_2019 %>% filter(rush == 1 | pass == 1) | |
offense <- plays %>% | |
group_by(offense_play) %>% | |
summarise(ypa = mean(yards_gained[pass==1]), | |
ypr = mean(yards_gained[rush==1]), | |
num.plays = n()) %>% | |
filter(num.plays > 300) | |
offense %>% arrange(desc(ypr)) | |
offense %>% arrange(desc(ypa)) | |
offense %>% arrange(ypa) | |
offense %>% arrange(ypr) | |
offense <- plays %>% group_by(offense_play) %>% | |
summarise(epa.pass.off = mean(EPA[pass==1]), | |
epa.rush.off = mean(EPA[rush==1]), | |
num.plays = n()) %>% | |
filter(num.plays > 300) | |
defense <- plays %>% group_by(defense_play) %>% | |
summarise(epa.pass.def = mean(EPA[pass==1]), | |
epa.rush.def = mean(EPA[rush==1]), | |
num.plays = n()) %>% | |
filter(num.plays > 300) | |
team_depa <- left_join(defense, offense, by = c("defense_play" = "offense_play")) | |
team.depa <- team_depa %>% left_join(cfblogos, by = c("defense_play" = "school")) | |
head(team.depa) | |
team.depa %>% ggplot(aes(x=epa.rush.def, y=epa.pass.def)) + geom_image(image = team.depa$logo, asp = 16/9) | |
team.depa %>% ggplot(aes(x=epa.rush.def, y=epa.pass.def)) + geom_image(image = team.depa$logo, asp = 16/9) + | |
geom_vline(xintercept = mean(team.depa$epa.rush.def), linetype = "dashed", color = "blue") + | |
geom_hline(yintercept = mean(team.depa$epa.pass.def), linetype = "dashed", color = "blue") + | |
labs(x = "Defensive Rush EPA/Play", y= "Defensive Pass EPA/Play", | |
title = "2019 NCAA Team Defensive Efficiency", | |
caption = "Data: @CFB_data with #cfbscrapR") + | |
theme_bw() + | |
theme(axis.title = element_text(size = 12), | |
axis.text = element_text(size = 10), | |
plot.title = element_text(size = 14), | |
plot.subtitle = element_text(size = 12), | |
plot.caption = element_text(size = 10)) | |
ggsave('team_depa_logos.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment