Created
February 4, 2026 22:15
-
-
Save cavedave/83c0718b9856c4b5157640f040d191cd to your computer and use it in GitHub Desktop.
ideological leanings of current USA supreme court judges https://en.wikipedia.org/wiki/Ideological_leanings_of_United_States_Supreme_Court_justices
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
| install.packages("readr", quiet = TRUE) | |
| library(readr) | |
| data https://mqscores.wustl.edu/measures.php | |
| justices_df <- read_csv("justices.csv") | |
| library(dplyr) | |
| library(ggplot2) | |
| # 1. Sitting Justices as of 2026 | |
| keep <- c("CThomas", "SAAlito", "JGRoberts", "EKagan", "SSotomayor", | |
| "ACBarrett", "KBJackson", "NMGorsuch", "BMKavanaugh") | |
| dems <- c("SSotomayor", "EKagan", "KBJackson") | |
| # 2. Manual Label Dataframe | |
| label_data <- data.frame( | |
| Party = c("Rep", "Rep", "Rep", "Dem", "Dem", "Rep", "Rep", "Rep", "Dem"), | |
| Name = c("Thomas", "Roberts", "Alito", "Sotomayor", "Kagan", | |
| "Gorsuch", "Kavanaugh", "Barrett", "Jackson"), | |
| nameYear = c(1995, 2006, 2004, 2007.5, 2009, 2015, 2017, 2019, 2021), | |
| nameNum = c(4.0, 0.8, 1.4, -2.0, -1.0, 1.0, 0.8, 1.2, -2.6) | |
| ) | |
| # 3. Filtering and Processing | |
| recent <- justices_df %>% | |
| filter(term >= 1991, justiceName %in% keep) %>% | |
| mutate(col = ifelse(justiceName %in% dems, "Democrat", "Republican")) | |
| # 4. Compact Plot Construction | |
| gg <- ggplot(recent) + | |
| geom_hline(yintercept = 0, alpha = 0.3, linetype = "dashed") + | |
| # Reference Labels | |
| annotate("label", x = 1991.5, y = 1.5, label = "More Conservative →", | |
| angle = 0, fontface = "bold", size = 3, fill = "white", label.size = 0) + | |
| annotate("label", x = 1991.5, y = -1.5, label = "← More Liberal", | |
| angle = 0, fontface = "bold", size = 3, fill = "white", label.size = 0) + | |
| # Data Layers | |
| geom_ribbon(aes(ymin = post_mn - post_sd, ymax = post_mn + post_sd, | |
| x = term, group = justiceName, fill = col), | |
| color = NA, alpha = 0.15) + | |
| geom_line(aes(x = term, y = post_med, color = col, group = justiceName), | |
| linewidth = 0.8) + | |
| # Justice Name Labels | |
| geom_text( | |
| data = label_data, | |
| aes(x = nameYear, y = nameNum, label = Name, | |
| color = ifelse(Party == "Dem", "Democrat", "Republican")), | |
| size = 4.2, fontface = "bold", show.legend = FALSE | |
| ) + | |
| # Axis Controls | |
| scale_x_reverse( | |
| limits = c(2025, 1991), | |
| breaks = c(2024, seq(2015, 1995, -10), 1991), | |
| labels = c(2024, seq(2015, 1995, -10), "1991↓"), | |
| expand = c(0, 0) | |
| ) + | |
| scale_y_continuous( | |
| limits = c(-5, 6), | |
| breaks = seq(-4, 6, 2), | |
| labels = function(x) ifelse(x == 0, "0\n(Neutral)", as.character(x)) | |
| ) + | |
| scale_color_manual(name = "Nominated by a", values = c(Democrat = "#2166ac", Republican = "#b2182b")) + | |
| scale_fill_manual(name = "Nominated by a", values = c(Democrat = "#2166ac", Republican = "#b2182b")) + | |
| coord_flip() + | |
| theme_minimal() + | |
| labs( | |
| title = "Current Supreme Court Justices Ideology (1991–2024)", | |
| subtitle = "Negative scores favor progressive, positive scores favor traditionalist interpretations.", | |
| caption = "Data: mqscores.wustl.edu | @iamreddave", | |
| x = "Term Year", y = NULL # REMOVED redundant y-axis label | |
| ) + | |
| theme( | |
| legend.position = "bottom", | |
| legend.box = "horizontal", | |
| legend.margin = margin(t = -5), # Pull legend closer to the graph | |
| plot.caption = element_text(size = 8, color = "grey40", vjust = 5.5, hjust = 1), # Align caption with legend | |
| plot.title = element_text(face = "bold"), | |
| axis.title.x = element_blank() # Further compacting the bottom | |
| ) | |
| print(gg) | |
Author
cavedave
commented
Feb 4, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment