Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Does Icing the Kicker Matter?
library(tidyverse)
library(nflscrapR)
library(ggthemes)
#I already have 2009 - Present data compiled. If you do not have NFL PBP data, see nflscrapR, @LeeSharpeNFL, or @BenBaldwin for their tutorials for pulling NFL pbpdata
kicking <- pbpfull %>%
select(posteam, defteam, desc, half_seconds_remaining, qtr, field_goal_attempt, field_goal_result, kick_distance, timeout, timeout_team, score_differential) %>%
mutate(timeoutbeforekick = ifelse(lag(timeout) == 1, 1, 0),
timeoutteam = ifelse(timeoutbeforekick == 1, lag(timeout_team), 0),
iced = ifelse(timeoutbeforekick == 1 & timeoutteam == defteam, 1, 0),
## When a kick is taken after the 2 minute warning, we get an NA, so let's correct for it
iced = ifelse(is.na(iced), 0, iced),
field_goal_make = ifelse(field_goal_result == "made", 1, 0)) %>%
filter(field_goal_attempt == 1,
qtr == 2 | qtr == 4,
half_seconds_remaining < 600,
score_differential <= 8 & score_differential >= -3,
## Apparently the Cleveland Browns refuse to mark how long their FG's are. It's only a few so let's remove them
!is.na(kick_distance)) %>%
group_by(iced, kick_distance) %>%
summarise(makes = sum(field_goal_make),
attempts = n(),
fgpercentage = (makes/attempts)*100)
iced <- filter(kicking, iced == 1)
regular <- filter(kicking, iced == 0)
ggplot(kicking, aes(x = kick_distance, y = fgpercentage)) +
geom_smooth(data = iced, color = "red", se = FALSE) +
geom_smooth(data = regular, color = "blue", se = FALSE) +
scale_color_fivethirtyeight() +
theme_fivethirtyeight() +
theme(axis.title = element_text(),
plot.caption = element_text(),
plot.title = element_text(hjust = .5),
plot.subtitle = element_text(hjust = .5)) +
xlab("Field Goal Distance") +
ylab("Make %") +
labs(title = "Does Icing the Kicker Work?",
subtitle = "Red = Iced, Blue = Non-Iced",
caption = "Data = @nflscrapR\nGraph = @ChiBearsStats\nQtr 2 & 4, <5 Min Remaining, 1 Score Game")
ggsave("Icing the Kicker.jpg", dpi = 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment