Created
June 9, 2025 18:26
-
-
Save acastroaraujo/c8d1f03014cb6d0eb0b358451d4208a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| library(tidyverse) | |
| judges_people <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-06-10/judges_people.csv') | |
| judges_appointments <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-06-10/judges_appointments.csv') | |
| judges_appointments <- judges_appointments |> | |
| mutate(across(ends_with("date"), lubridate::mdy)) | |
| scotus <- judges_appointments |> | |
| filter(str_detect(court_name, "Supreme Court of the United States")) |> | |
| mutate(end_date = if_else(is.na(termination_date), lubridate::mdy(retirement_from_active_service), termination_date)) |> | |
| mutate(end_date = if_else(is.na(end_date), as.Date("2015-01-01"), end_date)) |> | |
| left_join(judges_people) |> | |
| mutate(across(starts_with("name"), \(x) ifelse(is.na(x), "", x))) |> | |
| mutate(name = paste(name_first, name_middle, name_last)) |> | |
| mutate(name = ifelse(name == "John Marshall Harlan" & birth_date == 1899, paste(name, "II"), name)) |> | |
| mutate(chief = str_detect(court_name, "Chief")) | |
| scotus_names <- scotus |> | |
| arrange(commission_date) |> | |
| distinct(name, .keep_all = TRUE) |> | |
| filter(end_date > as.Date("1900-01-01")) |> | |
| mutate(name = reorder(name, commission_date)) | |
| scotus |> | |
| filter(end_date > as.Date("1900-01-01")) |> | |
| mutate(name = reorder(name, commission_date)) |> | |
| ggplot(aes(commission_date, name)) + | |
| geom_segment( | |
| data = filter(scotus, chief, end_date > as.Date("1900-01-01")), | |
| mapping = aes(xend = end_date, color = president_party), linewidth = 1 | |
| ) + | |
| geom_segment(aes(xend = end_date, color = president_party)) + | |
| geom_text( | |
| data = scotus_names, | |
| mapping = aes(label = name), size = 2, hjust = 1, nudge_x = -800, family = "Avenir Next Condensed" | |
| ) + | |
| scale_color_manual(values = c("blue", "red")) + | |
| labs(y = NULL, x = NULL, color = "Appointed by", title = "US Supreme Court", | |
| subtitle = "1900-2015") + | |
| scale_x_date(expand = c(1/4, 0), minor_breaks = "10 years", date_breaks = "20 years", date_labels = "%Y") + | |
| theme_minimal(base_family = "Avenir Next Condensed") + | |
| theme(axis.text.y = element_blank(), legend.position = "none", panel.grid.major.y = element_blank()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment