library(lubridate)library(dplyr)# List of affected dataframes and their namesdate_fix_dfs <-list("2012"= Illinois_Pop_2012,"2013"= Illinois_Pop_2013,"2014"= Illinois_Pop_2014,"2015"= Illinois_Pop_2015,"2016"= Illinois_Pop_2016,"2017"= Illinois_Pop_2017)# Columns to convertdate_columns <-c("date_of_birth","current_admission_date","projected_mandatory_supervised_released_(msr)_date2","projected_discharge_date2","custody_date","sentence_date")# Function to reformat MMDDYYYY-style dates to Date objectsfix_dates <-function(df) {for (col in date_columns) {if (col %in%colnames(df)) { df[[col]] <-suppressWarnings(mdy(as.character(df[[col]]))) } }return(df)}# Apply fix to all affected yearsIllinois_Pop_2012 <-fix_dates(Illinois_Pop_2012)Illinois_Pop_2013 <-fix_dates(Illinois_Pop_2013)Illinois_Pop_2014 <-fix_dates(Illinois_Pop_2014)Illinois_Pop_2015 <-fix_dates(Illinois_Pop_2015)Illinois_Pop_2016 <-fix_dates(Illinois_Pop_2016)Illinois_Pop_2017 <-fix_dates(Illinois_Pop_2017)
# List of all dataframesdata_list <-list( Illinois_Pop_2005, Illinois_Pop_2006, Illinois_Pop_2007, Illinois_Pop_2008, Illinois_Pop_2009, Illinois_Pop_2010, Illinois_Pop_2011, Illinois_Pop_2012, Illinois_Pop_2013, Illinois_Pop_2014, Illinois_Pop_2015, Illinois_Pop_2016, Illinois_Pop_2017, Illinois_Pop_2018, Illinois_Pop_2019, Illinois_Pop_2020, Illinois_Pop_2021, Illinois_Pop_2022, Illinois_Pop_2023, Illinois_Pop_2024)# Process each dataframe# Create the snapshot date for each yearlibrary(lubridate)snapshot_dates <-seq(ymd("2005-06-30"), ymd("2024-06-30"), by ="years")processed_data <-Map(process_df, data_list, snapshot_dates)
analysis_keep_cols <-c("idoc_#", "race", "sex", "sentence_date", "date_of_birth","sentence_years", "sentence_months", "year", "current_admission_date","crime_class", "holding_offense", "truth_in_sentencing","age_at_snapshot", "length_of_stay", "age_bracket", "emerging_adult")# Drop extra columns and mergeanalysis_data <-lapply(processed_data, function(df) { df[, intersect(analysis_keep_cols, names(df))]}) %>%bind_rows(.id ="year") %>%mutate(year =as.integer(year) +2004)
# Flag individuals who have served 15+ years at the time of snapshotanalysis_data <- analysis_data %>%mutate(long_term_served =ifelse(length_of_stay >=15, TRUE, FALSE))
ggplot(long_term_summary, aes(x = year, y = long_term_percent)) +geom_line(size =1.2, color ="firebrick") +geom_point(size =2, color ="firebrick") +labs(title ="Growth of Individuals Who Have Served 15+ Years in Prison (Illinois, 2005–2024)",x ="Year",y ="Percent of Prison Population",caption ="Source: IDOC snapshot data, June 30th each year" ) +theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
aging_trends <- analysis_data %>%filter(age_bracket %in%c("55-64", "65-74", "75+")) %>%group_by(year, age_bracket) %>%summarise(count =n(), .groups ="drop")ggplot(aging_trends, aes(x = year, y = count, color = age_bracket)) +geom_line(size =1.2) +labs(title ="Aging Prison Population in Illinois (2005–2024)",x ="Year",y ="Number of Incarcerated Individuals",color ="Age Bracket" ) +theme_minimal()
long_term_trend <- analysis_data %>%mutate(long_term = sentence_years >=15) %>%group_by(year) %>%summarise(total =n(),long_term =sum(long_term, na.rm =TRUE),percent_long_term =round(100* long_term / total, 1),.groups ="drop" )ggplot(long_term_trend, aes(x = year, y = percent_long_term)) +geom_line(size =1.2, color ="firebrick") +labs(title ="Share of People Serving Long Prison Terms (15+ years)",x ="Year",y ="Percent (%)" ) +theme_minimal()
race_long_term <- analysis_data %>%filter(sentence_years >=15) %>%group_by(year, race) %>%summarise(count =n(), .groups ="drop")ggplot(race_long_term, aes(x = year, y = count, color = race)) +geom_line(size =1.2) +labs(title ="Racial Disparities in Long Prison Terms (15+ years)",x ="Year",y ="Number of People",color ="Race" ) +theme_minimal()
long_term_by_sex <- analysis_data %>%group_by(year, sex) %>%summarise(total =n(),long_term =sum(long_term_served, na.rm =TRUE),percent_long_term =round(100* long_term / total, 1),.groups ="drop" )ggplot(long_term_by_sex, aes(x = year, y = percent_long_term, color = sex)) +geom_line(size =1.2) +labs(title ="Percent of Prison Population Who Have Served 15+ Years (By Sex)",x ="Year", y ="Percent (%)",color ="Sex" ) +theme_minimal()
emerging_adults_long_term <- analysis_data %>%filter(emerging_adult ==TRUE) %>%group_by(year) %>%summarise(count =n(),.groups ="drop" )ggplot(emerging_adults_long_term, aes(x = year, y = count)) +geom_line(color ="darkgreen", size =1.2) +geom_point(size =2, color ="darkgreen") +labs(title ="Emerging Adults Serving 15+ Years: Snapshot Growth Over Time",x ="Year",y ="Number of People",caption ="Emerging adults = under 25 at time of admission and served 15+ years" ) +theme_minimal()
long_term_by_race <- analysis_data %>%group_by(year, race) %>%summarise(total =n(),long_term =sum(long_term_served, na.rm =TRUE),percent_long_term =round(100* long_term / total, 1),.groups ="drop" )ggplot(long_term_by_race, aes(x = year, y = percent_long_term, color = race)) +geom_line(size =1.2) +labs(title ="Percent of Prison Population Who Have Served 15+ Years (By Race)",x ="Year", y ="Percent (%)",color ="Race" ) +theme_minimal()
aging_data <- analysis_data %>%filter(age_bracket %in%c("55-64", "65-74", "75+"))aging_by_year <- aging_data %>%group_by(year, age_bracket) %>%summarise(count =n(), .groups ="drop")ggplot(aging_by_year, aes(x = year, y = count, color = age_bracket)) +geom_line(size =1.2) +geom_point(size =2) +labs(title ="Growth of Aging Prison Population in Illinois (Ages 55+)",x ="Year",y ="Number of Incarcerated People",color ="Age Bracket",caption ="Source: IDOC snapshot data" ) +theme_minimal()
aging_summary <- analysis_data %>%mutate(is_aging = age_at_snapshot >=55) %>%group_by(year) %>%summarise(total =n(),aging_count =sum(is_aging, na.rm =TRUE),percent_aging =round(100* aging_count / total, 1),.groups ="drop" )ggplot(aging_summary, aes(x = year, y = percent_aging)) +geom_line(size =1.2, color ="steelblue") +geom_point(size =2, color ="steelblue") +labs(title ="Percent of Illinois Prison Population Aged 55 and Older",x ="Year", y ="Percent (%)",caption ="Includes all individuals age 55+ at snapshot" ) +theme_minimal()
aging_by_race <- aging_data %>%group_by(year, race) %>%summarise(count =n(), .groups ="drop")ggplot(aging_by_race, aes(x = year, y = count, color = race)) +geom_line(size =1.2) +labs(title ="Aging Prison Population (55+) by Race",x ="Year", y ="Number of People",color ="Race" ) +theme_minimal()
aging_by_sex <- aging_data %>%group_by(year, sex) %>%summarise(count =n(), .groups ="drop")ggplot(aging_by_sex, aes(x = year, y = count, color = sex)) +geom_line(size =1.2) +labs(title ="Aging Prison Population (55+) by Sex",x ="Year", y ="Number of People",color ="Sex" ) +theme_minimal()