Shortlink: https://git.io/JUzIr
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
# Code: https://git.io/JUzIr | |
library(tidyverse) | |
library(ggtext) | |
adv_stats <- team_def %>% | |
left_join( | |
nflfastR::teams_colors_logos %>% | |
select(team = team_name, team_color, team_logo_espn) %>% | |
distinct(team, .keep_all = TRUE) | |
) | |
summary_df <- adv_stats %>% | |
summarize( | |
blitz_pct = mean(blitz_pct), | |
pressure_pct = mean(pressure_pct) | |
) | |
blitz_plot <- adv_stats %>% | |
ggplot(aes(x = blitz_pct, y = pressure_pct)) + | |
ggimage::geom_image(aes(image = team_logo_espn), by = "height", size = 0.08, asp = 1.618) + | |
ggtext::geom_richtext( | |
data = steelers_df, nudge_x = 0.01, | |
fill = NA, label.color = NA, # remove background and outline | |
hjust = 0, size = 6, | |
aes(label = label) | |
) + | |
geom_hline(yintercept = pull(summary_df, pressure_pct), color = "red", linetype = "dashed") + | |
geom_vline(xintercept = pull(summary_df, blitz_pct), color = "red", linetype = "dashed") + | |
scale_x_continuous(breaks = scales::pretty_breaks(n = 8), labels = scales::percent_format(accuracy = 1)) + | |
scale_y_continuous(breaks = scales::pretty_breaks(n = 8), labels = scales::percent_format(accuracy = 1)) + | |
theme_minimal() + | |
theme( | |
panel.grid.minor = element_blank(), | |
aspect.ratio = 1 / 1.618, | |
plot.title = element_text(size = 28, face = "bold"), | |
plot.subtitle = element_text(size = 22), | |
plot.caption = ggtext::element_markdown(size = 18), | |
axis.title = element_text(size = 20, face = "bold"), | |
axis.text = element_text(size = 16) | |
) + | |
labs( | |
title = "Blitz Rate vs Pressure Rate", | |
subtitle = "2020 Season", | |
x = "\nBlitz Rate\n", | |
y = "Pressure Rate\n", | |
caption = "**Data:** ProFootball Reference | **Plot:** @thomas_mock" | |
) | |
blitz_plot | |
ggsave("blitz_plot.png", plot = blitz_plot, height = 10, width = 10 * 1.618, dpi = "retina") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment