Skip to content

Instantly share code, notes, and snippets.

@mrcaseb
Created March 24, 2022 17:29
Show Gist options
  • Save mrcaseb/0e51e60744849445e04e9d02d5b638c1 to your computer and use it in GitHub Desktop.
Save mrcaseb/0e51e60744849445e04e9d02d5b638c1 to your computer and use it in GitHub Desktop.
library(tidyverse)
drafts <- nflreadr::load_draft_picks()
draft_order <- rvest::read_html("https://en.wikipedia.org/wiki/2022_NFL_Draft") |>
rvest::html_table() |>
purrr::pluck(5) |>
janitor::clean_names() |>
select(round = rnd, pick = pick_no, team = nfl_team, notes) |>
mutate(across(c(round, pick), as.numeric)) |>
mutate(season = 2022) |>
na_if("")
df <- drafts |>
bind_rows(draft_order) |>
filter(round == 1) |>
group_by(season) |>
summarise(
n_teams = n_distinct(team),
n_picks = n()
) |>
mutate(
first_round_rate = n_teams / n_picks
)
col <- "#F47B00FF"
current_year <- 2022
current_data <- df |> filter(season == current_year)
anno_text <- glue::glue("As of today, only {current_data$n_teams} of {current_data$n_picks} NFL teams\nhave a first-round pick in the {current_year} draft.\nThe lowest percentage since at least {min(df$season)}.")
p <- ggplot(df, aes(x = forcats::fct_reorder(as.factor(season), first_round_rate), y = first_round_rate)) +
geom_segment(aes(xend = forcats::fct_reorder(as.factor(season), first_round_rate), yend = 0.75), color = "grey50") +
geom_point(color = col, size = 3) +
scale_y_continuous(labels = scales::percent, breaks = seq(0.75, 1, 0.05), limits = c(0.75, 1)) +
scale_x_discrete("Draftyear", labels = function(x) paste0("'", substr(x,3,4))) +
labs(
y = tools::toTitleCase("Percentage of NFL teams having a 1st round pick"),
caption = glue::glue("Figure:@mrcaseb | Data:@pfref | {lubridate::today()}")
) +
ggthemes::theme_fivethirtyeight(base_size = 11, base_family = "Roboto Condensed") +
theme(
plot.title.position = "plot",
panel.grid.major.x = element_blank(),
axis.title = element_text()
) +
annotate("curve",
x = "1986", y = 0.955,
xend = "2022", yend = 0.755,
curvature = 0.1, arrow = arrow(type = "closed", length = unit(0.15, "inches"), angle = 20),
color = "#0C46A0FF"
) +
annotate("label",
x = "1986", y = 0.975,
label = anno_text,
hjust = 0, vjust = 0.5,
family = "Roboto Condensed",
fill = "#F0F0F0",
size = 6, color = "#0C46A0FF"
) +
NULL
p
@mrcaseb
Copy link
Author

mrcaseb commented Mar 24, 2022

first_round_percentage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment