Introduction

In this lab, I used U.S. Census Bureau American Community Survey (ACS) data to explore social and economic patterns across counties in Mississippi. The goal of this analysis is to understand differences in graduate degree and employment across counties, and to visualize these patterns using both static and interactive graphics. This project also demonstrates how different types of data (percentages vs. raw counts) require different visualization approaches. I created three main outputs: a static margin-of-error plot, an interactive version of the same plot, and a map visualization to show geographic patterns in employment.

Data Preparation

To begin, I used the tidycensus package to access ACS data. Before retrieving the data, I got my Census API key so that I could download data directly from the Census website.

# Get Census API key 
census_api_key("7712f4050792f95cda2b3af671fd0eaf1f8129c4", install = TRUE, overwrite=TRUE)
## Your original .Renviron will be backed up and stored in your R HOME directory if needed.
## Your API key has been stored in your .Renviron and can be accessed by Sys.getenv("CENSUS_API_KEY"). 
## To use now, restart R or run `readRenviron("~/.Renviron")`
## [1] "7712f4050792f95cda2b3af671fd0eaf1f8129c4"

Next, I retrieved data for the percentage of the population with a graduate degree using the variable DP02_0066P. This variable represents a percentage, meaning it is already standardized and allows for fair comparisons across counties.

## Getting data from the 2017-2021 5-year ACS
## Using the ACS Data Profile

I also explored the dataset using View() to better understand its structure, including the estimate (value) and margin of error (moe).To identify counties with the highest and lowest values, I separated the county and state names and filtered the data:

View(grad_degree_pct)

grad_degree_pct_table <- get_acs(
  geography = "county",
  state = "MS",
  variables = "DP02_0066P",
  year = 2021
)
## Getting data from the 2017-2021 5-year ACS
## Using the ACS Data Profile
grad_degree_pct_table
## # A tibble: 82 × 5
##    GEOID NAME                          variable   estimate   moe
##    <chr> <chr>                         <chr>         <dbl> <dbl>
##  1 28001 Adams County, Mississippi     DP02_0066P      8     1.6
##  2 28003 Alcorn County, Mississippi    DP02_0066P      6.4   1.5
##  3 28005 Amite County, Mississippi     DP02_0066P      4.8   1.5
##  4 28007 Attala County, Mississippi    DP02_0066P      3.8   1.1
##  5 28009 Benton County, Mississippi    DP02_0066P      5     2.2
##  6 28011 Bolivar County, Mississippi   DP02_0066P     11.2   1.8
##  7 28013 Calhoun County, Mississippi   DP02_0066P      4.8   1.2
##  8 28015 Carroll County, Mississippi   DP02_0066P      3.8   2  
##  9 28017 Chickasaw County, Mississippi DP02_0066P      3.1   0.9
## 10 28019 Choctaw County, Mississippi   DP02_0066P      8.3   1.9
## # ℹ 72 more rows
# Find highest value
highest_grad_pct <- grad_degree_pct %>%
  separate(NAME, into = c("county", "state"), sep = ", ") %>%
  group_by(state) %>%
  filter(estimate == max(estimate, na.rm = TRUE))
# Find lowest value
lowest_grad_pct <- grad_degree_pct %>%
  separate(NAME, into = c("county", "state"), sep = ", ") %>%
  group_by(state) %>%
  filter(estimate == min(estimate, na.rm = TRUE))
highest_grad_pct
## # A tibble: 1 × 6
## # Groups:   state [1]
##   GEOID county           state       variable   estimate   moe
##   <chr> <chr>            <chr>       <chr>         <dbl> <dbl>
## 1 28105 Oktibbeha County Mississippi DP02_0066P     22.5     2

Oktibbeha County is highest

lowest_grad_pct
## # A tibble: 1 × 6
## # Groups:   state [1]
##   GEOID county         state       variable   estimate   moe
##   <chr> <chr>          <chr>       <chr>         <dbl> <dbl>
## 1 28103 Noxubee County Mississippi DP02_0066P      2.7   1.4

Noxubee County is the lowest

##Margin of Error Plot

I created a margin of error plot to show the percentage of the population with a graduate degree across counties in Mississippi, including the uncertainty around each estimate. The points represent the estimates, and the horizontal lines show the margins of error from the ACS data.

This method is useful for comparing counties and understanding data reliability. However, because Mississippi has many counties, the plot becomes crowded and harder to read. I think this method works, but it is less effective for states with a large number of geographic units.

# Plot
md_plot_errorbar <- ggplot(grad_degree_pct, 
                          aes(x = estimate, 
                              y = reorder(NAME, estimate))) + 
  
  # Margin of error bars
  geom_errorbar(aes(xmin = estimate - moe, 
                    xmax = estimate + moe),
                width = 0.2, 
                linewidth = 0.4, 
                color = "gray50") +
  
  # Points
  geom_point(color = "darkred", size = 2) +
  
  # Format x-axis as percentage
  scale_x_continuous(labels = function(x) paste0(x, "%")) +
  
  # Clean county names
  scale_y_discrete(labels = function(x) 
    str_remove(x, " County, Mississippi|, Mississippi")) +
  
  # Labels
  labs(
    title = "Graduate Degree Percentage by County (2021 ACS)",
    subtitle = "Mississippi (2021 American Community Survey)",
    caption = "Points show estimates; horizontal lines indicate margins of error",
    x = "Percent of population with a graduate degree",
    y = NULL
  ) +
  
  # Theme 
  theme_minimal(base_size = 11) +
  theme(
    axis.text.y = element_text(size = 5),  # smaller text to reduce clutter
    plot.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  )

Interactive Plots.

Use the plotly package to convert the plot to an interactive chart.

md_plot_errorbar

Use the ggiraph package to make the plot interactive chart.

# Interactive Plot
ggplotly(md_plot_errorbar, tooltip = "x")
md_plot_ggiraph <- md_plot_errorbar
girafe(ggobj = md_plot_ggiraph) %>%
  girafe_options(opts_hover(css = "fill:cyan;"))

Use the load_variables() function to find a variable that interests me the most which is the EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OLDER.

vars <- load_variables(2021, "acs5")
View(vars)
#B23025_003

Interactive Map (mapview)

This map displays employment counts across counties. Because the data represents raw counts.

emplyment_16andOlder <- get_acs(
  geography = "county",
  state = "MS",
  variables = "B23025_003",
  year = 2021,
  geometry = TRUE 
)
## Getting data from the 2017-2021 5-year ACS
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
##   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |===                                                                   |   4%  |                                                                              |===                                                                   |   5%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |=========                                                             |  14%  |                                                                              |==========                                                            |  14%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |===========                                                           |  16%  |                                                                              |============                                                          |  16%  |                                                                              |============                                                          |  17%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |==============                                                        |  21%  |                                                                              |===============                                                       |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  22%  |                                                                              |================                                                      |  23%  |                                                                              |================                                                      |  24%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |===================                                                   |  28%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |=====================                                                 |  31%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |==========================                                            |  38%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  39%  |                                                                              |============================                                          |  40%  |                                                                              |============================                                          |  41%  |                                                                              |=============================                                         |  41%  |                                                                              |=============================                                         |  42%  |                                                                              |==============================                                        |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |=================================                                     |  48%  |                                                                              |==================================                                    |  48%  |                                                                              |==================================                                    |  49%  |                                                                              |===================================                                   |  49%  |                                                                              |===================================                                   |  50%  |                                                                              |===================================                                   |  51%  |                                                                              |====================================                                  |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |=====================================                                 |  54%  |                                                                              |======================================                                |  54%  |                                                                              |======================================                                |  55%  |                                                                              |=======================================                               |  55%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  56%  |                                                                              |========================================                              |  57%  |                                                                              |========================================                              |  58%  |                                                                              |=========================================                             |  58%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |==========================================                            |  61%  |                                                                              |===========================================                           |  61%  |                                                                              |===========================================                           |  62%  |                                                                              |============================================                          |  62%  |                                                                              |============================================                          |  63%  |                                                                              |============================================                          |  64%  |                                                                              |=============================================                         |  64%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |===============================================                       |  68%  |                                                                              |================================================                      |  68%  |                                                                              |================================================                      |  69%  |                                                                              |=================================================                     |  69%  |                                                                              |=================================================                     |  70%  |                                                                              |=================================================                     |  71%  |                                                                              |==================================================                    |  71%  |                                                                              |==================================================                    |  72%  |                                                                              |===================================================                   |  72%  |                                                                              |===================================================                   |  73%  |                                                                              |====================================================                  |  74%  |                                                                              |====================================================                  |  75%  |                                                                              |=====================================================                 |  75%  |                                                                              |=====================================================                 |  76%  |                                                                              |======================================================                |  77%  |                                                                              |======================================================                |  78%  |                                                                              |=======================================================               |  78%  |                                                                              |=======================================================               |  79%  |                                                                              |========================================================              |  79%  |                                                                              |========================================================              |  80%  |                                                                              |========================================================              |  81%  |                                                                              |=========================================================             |  81%  |                                                                              |=========================================================             |  82%  |                                                                              |==========================================================            |  82%  |                                                                              |==========================================================            |  83%  |                                                                              |===========================================================           |  84%  |                                                                              |===========================================================           |  85%  |                                                                              |============================================================          |  85%  |                                                                              |============================================================          |  86%  |                                                                              |=============================================================         |  86%  |                                                                              |=============================================================         |  87%  |                                                                              |=============================================================         |  88%  |                                                                              |==============================================================        |  88%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |===============================================================       |  91%  |                                                                              |================================================================      |  91%  |                                                                              |================================================================      |  92%  |                                                                              |=================================================================     |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |=================================================================     |  94%  |                                                                              |==================================================================    |  94%  |                                                                              |==================================================================    |  95%  |                                                                              |===================================================================   |  95%  |                                                                              |===================================================================   |  96%  |                                                                              |====================================================================  |  96%  |                                                                              |====================================================================  |  97%  |                                                                              |====================================================================  |  98%  |                                                                              |===================================================================== |  98%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================|  99%  |                                                                              |======================================================================| 100%
centroids <- st_centroid(emplyment_16andOlder)
## Warning: st_centroid assumes attributes are constant over geometries
emplyment_16andOlder
## Simple feature collection with 82 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -91.65501 ymin: 30.17394 xmax: -88.09789 ymax: 34.99605
## Geodetic CRS:  NAD83
## First 10 features:
##    GEOID                        NAME   variable estimate  moe
## 1  28079   Leake County, Mississippi B23025_003     8688  509
## 2  28121  Rankin County, Mississippi B23025_003    80190 1560
## 3  28001   Adams County, Mississippi B23025_003    11437  682
## 4  28145   Union County, Mississippi B23025_003    12915  450
## 5  28051  Holmes County, Mississippi B23025_003     5819  432
## 6  28073   Lamar County, Mississippi B23025_003    31298 1060
## 7  28131   Stone County, Mississippi B23025_003     7708  585
## 8  28143  Tunica County, Mississippi B23025_003     4672  258
## 9  28083 Leflore County, Mississippi B23025_003    11205  578
## 10 28013 Calhoun County, Mississippi B23025_003     5656  294
##                          geometry
## 1  MULTIPOLYGON (((-89.7303 32...
## 2  MULTIPOLYGON (((-90.25346 3...
## 3  MULTIPOLYGON (((-91.65501 3...
## 4  MULTIPOLYGON (((-89.24626 3...
## 5  MULTIPOLYGON (((-90.43168 3...
## 6  MULTIPOLYGON (((-89.65421 3...
## 7  MULTIPOLYGON (((-89.34139 3...
## 8  MULTIPOLYGON (((-90.59178 3...
## 9  MULTIPOLYGON (((-90.45376 3...
## 10 MULTIPOLYGON (((-89.50975 3...
emplymentCount<-emplyment_16andOlder
mapview(emplymentCount, zcol = "estimate")

Static Map (ggplot2 – Graduated Symbols)

To better represent raw counts, I created a graduated symbols map where circle size reflects employment totals

ggplot(emplyment_16andOlder) +
  geom_sf(aes(fill = estimate), color = "black", fill = "lightgrey") +
  geom_sf(data = centroids, aes(size = estimate),
          alpha = 0.7, color = "navy") + 
  theme_void() + 
  labs(
    title = "Total Employment (Age 16+) by County",
    subtitle = "Mississippi- 2021 ACS",
    caption = "Source: U.S. Census Bureau ACS (5-Year Estimates)"
  ) +
  theme_minimal() +
  scale_size_area(max_size = 6)