Very few judges have been women, historically speaking. Judgeships are lifetime appointments and the data indicates that most stay in their position 20+ years.
Sankey Diagram
R
Author
Steven Villalon
Published
June 10, 2025
Question of Interest
In a single chart, demonstrate the ratio of nominations that came from each party, the gender of nominees, and how long they served.
Goal: Make a Sankey diagram showing the flow of nominations through gender and length of service.
# Load data from tidytuesdayR packagetuesdata <- tidytuesdayR::tt_load(tt_date)# Extract elements from tuesdataappointments <- tuesdata$judges_appointmentspeople <- tuesdata$judges_people# Remove tuesdata filerm(tuesdata)
3. Examine Data
Show Code
# View datahead(appointments)
# A tibble: 6 × 15
judge_id court_name court_type president_name president_party nomination_date
<dbl> <chr> <chr> <chr> <chr> <chr>
1 3419 U. S. Dist… USDC Barack Obama Democratic 07/28/2011
2 1 U. S. Dist… USDC Franklin D. R… Democratic 02/03/1936
3 2 U. S. Dist… USDC Rutherford B.… Republican 01/06/1880
4 3 U. S. Dist… USDC Ronald Reagan Republican 07/22/1982
5 4 U. S. Dist… USDC Jimmy Carter Democratic 09/28/1979
6 5 U. S. Dist… USDC Gerald Ford Republican 06/18/1976
# ℹ 9 more variables: predecessor_last_name <chr>,
# predecessor_first_name <chr>, senate_confirmation_date <chr>,
# commission_date <chr>, chief_judge_begin <dbl>, chief_judge_end <dbl>,
# retirement_from_active_service <chr>, termination_date <chr>,
# termination_reason <chr>
Show Code
head(people)
# A tibble: 6 × 13
judge_id name_first name_middle name_last name_suffix birth_date
<dbl> <chr> <chr> <chr> <chr> <dbl>
1 3419 Ronnie <NA> Abrams <NA> 1968
2 1 Matthew T. Abruzzo <NA> 1889
3 2 Marcus Wilson Acheson <NA> 1828
4 3 William Marsh Acker Jr. 1927
5 4 Harold Arnold Ackerman <NA> 1928
6 5 James Waldo Ackerman <NA> 1926
# ℹ 7 more variables: birthplace_city <chr>, birthplace_state <chr>,
# death_date <dbl>, death_city <chr>, death_state <chr>, gender <chr>,
# race <chr>
# Convert dates from character to Date type and calculate service lengthdf <- df |>mutate(start_date =as.Date(commission_date, format ="%m/%d/%Y"),end_date =as.Date(termination_date, format ="%m/%d/%Y"),end_date =if_else(is.na(end_date),Sys.Date(), end_date),length_of_service =round(as.numeric(end_date - start_date) /365.25, 1) )
# Group data for the Sankeyagg_df <-as.data.frame(table(df$president_party_grouped, df$gender, df$length_of_service))# Add column namescolnames(agg_df) <-c("presidents_party", "judge_gender", "service_length", "freq")# Re-order factor levelsagg_df$service_length <-fct_relevel(agg_df$service_length, c("0 - 5 years","5 - 10 years", "10 - 15 years", "15 - 20 years", "20+ years"))
5. Visualization
Show Code
# Load fontfont_add_google("Merriweather", "merriweather")showtext_auto()showtext_opts(dpi =300)# Make plotfinal_plot <-ggplot(agg_df) +aes(axis1 = presidents_party,axis2 = judge_gender,axis3 = service_length,y = freq ) +geom_alluvium(aes(fill = presidents_party),width =1/12 ) +scale_fill_manual(values =c("Democrat"="#3B77AF","Republican"="#C43D35" )) +geom_stratum(width =0.4,fill ="gray80" ) +geom_text(stat ="stratum",aes(label =after_stat(stratum)),family ="merriweather",color ="#4A4A4A" ) +scale_x_discrete(limits =c("President's Party", "Gender", "Service Length"),expand =c(0.1, 0.1) ) +scale_y_continuous(labels = scales::comma) +theme_minimal(base_family ="merriweather") +labs(title ="U.S. Judge Appointments Since 1789",subtitle ="Federal appointments are a big deal because most judges end up serving more than 20 years. \nRepublican presidents have appointed 208 more judges than Democratic presidents. Historically, \nmost judges have been men, but women are increasingly holding these positions.",y ="Appointments",caption ="\nChart produced by Steven Villalon for Tidy Tuesday exercise on June 10, 2025." ) +theme(plot.background =element_rect(fill ="#EFDECD"),panel.background =element_rect(fill ="#EFDECD"),panel.grid =element_blank(),legend.position ="none",plot.margin =margin(t =20, r =20, b =20, l =20),plot.title =element_text(face ="bold",size =20,color ="#8A3324" ),plot.subtitle =element_text(size =10,color ="gray30" ),plot.caption =element_text(hjust =0,color ="gray30" ),axis.text.x =element_text(size =12,color ="gray30" ),axis.title.y =element_text(size =12,color ="gray30",margin =margin(r =10) ) )final_plot
6. Export Visualization
Show Code
# Select file formats to export toformats_to_export <-c("png", "svg")# Save files to the output folder (uses custom R script)save_tt_plots(plot = final_plot, title = title, date = tt_date,output_folder ="output", formats = formats_to_export, height =6,width =8,dpi =300 )