Introduction

Illinois, situated almost in the center of the United States, boasts a strong reputation as one of the top-educated and most-populous states in the country, with one of the largest economies (America Counts Staff, 2021). How is its education and wealth distributed at the county level?

This report explores American Community Survey (ACS) data for Illinois from 2023, revealing the counties which have the largest and smallest percentages of graduate degree holders, as well as income by county, to get a better picture of how Illinois counties measure up against each other.


Data Preparation

Load Necessary Packages

library(tidycensus)
library(tidyverse)
library(scales)
library(plotly)
library(mapview)

Retrieve ACS Data

First, I will use the tidycensus function get_acs() to locate data based on parameters for spatial resolution, table, year, and state.

degrees_il <- get_acs(
  geography = "county",
  
  # give the variable a more human-readable name
  variables = c(percent_graduate = "DP02_0066P"),
  year = 2023,
  state = "IL"
)

# arrange percent estimates in descending order
arrange(degrees_il, desc(estimate))
## # A tibble: 102 × 5
##    GEOID NAME                       variable         estimate   moe
##    <chr> <chr>                      <chr>               <dbl> <dbl>
##  1 17019 Champaign County, Illinois percent_graduate     25.5   1.1
##  2 17043 DuPage County, Illinois    percent_graduate     21     0.4
##  3 17097 Lake County, Illinois      percent_graduate     19.5   0.5
##  4 17031 Cook County, Illinois      percent_graduate     17.6   0.2
##  5 17077 Jackson County, Illinois   percent_graduate     16.8   1.2
##  6 17113 McLean County, Illinois    percent_graduate     15.7   0.8
##  7 17109 McDonough County, Illinois percent_graduate     15.1   1.7
##  8 17167 Sangamon County, Illinois  percent_graduate     14.2   0.6
##  9 17133 Monroe County, Illinois    percent_graduate     14     1.9
## 10 17143 Peoria County, Illinois    percent_graduate     13.7   0.8
## # ℹ 92 more rows

Champaign County has the largest estimated percentage of graduate degree holders at 25.5% and a margin of error of 1.1%. DuPage and Lake counties follow with margins of error at 0.4% and 0.5% respectively. Rows 1-10 are currently visible out of 102. It’s difficult to conceptualize the differences between counties by viewing the table, so I will next create a plot depicting all 102 counties with their estimates.


Analysis Part A: Visualization & Analysis with ggplot and plotly

To make the data for all 102 counties visible, I’ll plot the data with ggplot().

# since Illinois has 102 counties, in order to not have y-axis labels values overlap, the dimensions for this code chunk's output are specified as:
# #| fig-height: 15 
# #| fig-width: 10
# #| dpi: 300

degree_plot_errorbar <- ggplot(degrees_il, aes(x = estimate,
                                      y = reorder(NAME, estimate))) +
  
  # create and stylize the error bars
  geom_errorbar(aes(xmin = estimate - moe, xmax = estimate + moe),
                width = 0.5, linewidth = 0.5, color = "black") +
  
  # similarly, create points
  geom_point(color = "blue", size = 1.5) +
  scale_x_continuous(labels = label_percent(scale = 1)) +
  
  # clean y-axis labels
  scale_y_discrete(labels = function(x) str_remove(x, " County, Illinois")) +
  
  # customize labels
  labs(
    title = "Percent of Population with Graduate Degrees, 2023 ACS",
    subtitle = "Counties in Illinois",
    caption = "Data acquired with R and tidycensus. Error bars represent margin of error around estimates.",
    x = "ACS Estimate",
    y = "") +
  
  theme_minimal()

degree_plot_errorbar

With the values all plotted, it becomes clear that while Champaign County ranks in at first place for estimated percent of population with a graduate degree, Brown County comes in last place, followed by Perry and Shelby counties at second- and third-to-last, respectively.

We can see that Brown County’s percent value is somewhere between 3% and 4%, but we can’t tell exactly what it is just by looking at this plot.

To provide the exact percent values for each point, I will plot the data in an interactive plot using the ggplotly() function.

ggplotly(degree_plot_errorbar, tooltip = "x", height = 1700)

Now we can see that Brown county’s percent estimate is 3.4% when hovering over the data point. However, its margin of error bar shows that the true percent value could be anywhere from around 2% to 4%, which means it’s possible that Brown County could actually place anywhere in the bottom 30-40 counties, as these counties all show overlapping margins of error with Brown County (with the exception of Marion County).


Analysis Part B: Spatial Visualization & Analysis of Income Data

Now that I have created an interactive plot and analyzed the data for the percent of graduate degrees in Illinois Counties, I will explore a variable from the ACS data that often correlates with education status: income.

Data Preparation: Retrieving ACS Income Data

I will first view the variables available for 2023 with load_variables().

vars <- load_variables(2023, "acs5") # load possible variables

view(vars) # view variables table

After locating my desired variable (income), I will next use mapview() to plot income estimates by county in an interactive map.

income_il <- get_acs(
  geography = "county",
  variables = "B19013_001",
  state = "IL",
  year = 2023,
  geometry = TRUE
)
mapview(income_il, zcol = "estimate")

This interactive choropleth map is a nice basic visual that shows the counties surrounding Cook County (Will, Kendall, DuPage, and Lake, notably) as earning the largest median incomes. Next, I will create a static choropleth map with clearer labels.


Creating a static choropleth symbol map with ggplot() and geom_sf()

# create choropleth map of income_il
income_il_static <- ggplot(income_il) +
  geom_sf(aes(fill = estimate), color = "white") +
  
  # customize theme
  theme_void() +
  
  # format dollar values with label = label_dollar()
  scale_fill_viridis_c(labels = label_dollar()) +
  
  # customize labels
  labs(title = "Median Income by County",
       subtitle = "Illinois Counties, 2023",
       fill = "ACS Estimate",
       caption = "2023 ACS | tidycensus R package")  

income_il_static

The resulting choropleth map depicts the same information viewable in the interactive map, now available to save as an image file.

ggsave(“income_il.png”, plot = income_il_static)

ggsave("income_il.png", plot = income_il_static, dpi = 300)

References

America Counts Staff. (2021, August 25). Illinois population down 0.1% in 2020. U.S. Census Bureau. https://www.census.gov/library/stories/state-by-state/illinois.html