Skip to content

Instantly share code, notes, and snippets.

@friscojosh
Created February 18, 2018 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friscojosh/2071aad18a57fb1a926fc0baebdbbd0f to your computer and use it in GitHub Desktop.
Save friscojosh/2071aad18a57fb1a926fc0baebdbbd0f to your computer and use it in GitHub Desktop.
library(tidyverse)
passes <- read_csv('data/third_and_long_pass_plays.csv')
grouped_passes <- passes %>%
group_by(air_yards) %>%
summarize(catch_rate = mean(passing_cmp)) %>%
filter(air_yards !=0) %>%
filter(air_yards >= -4)
lg_avg_completion_percentage <- function(p) {
0.00028 * p ^ 2 - 0.0239 * p + 0.787
}
ggplot(grouped_passes, aes(x = air_yards, y = catch_rate)) +
theme_minimal() +
theme(plot.title=element_text(size=16, hjust=0, vjust=-1),
plot.subtitle=element_text(size=12, hjust=0)) +
stat_function(fun = lg_avg_completion_percentage, color = '#FFB704') +
geom_point(alpha=.4, color='#018417') +
geom_hline(yintercept = 0, alpha = .4) +
geom_smooth(
fill = '#CCCCCC',
alpha = .2,
color = '#018417',
size = .6,
span = .3
) +
scale_x_continuous(
limit = c(-5, 50),
breaks = c(seq(
from = -5,
to = 50,
by = 5
)),
minor_breaks = NULL
) +
scale_y_continuous(
limit = c(0, 1),
breaks = c(seq(
from = 0,
to = 1,
by = .1
)),
minor_breaks = NULL,
labels = scales::percent
) +
labs(fill = "Player name", x = "Depth of Target", y = "Completion Percentage",
title = "Completion Percentage by Depth on 3rd Down and Long", subtitle = "(Note: 2009-2016 league average completion percentage in orange)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment