For this analysis, I examine the relationship between educational attainment and median household income across the 95 counties in Tennessee using data from the 2023 American Community Survey (ACS). The project investigates whether counties with higher percentages of adults holding a bachelor’s degree or higher also tend to have higher median household incomes. Using correlation analysis, linear regression, and visualizations such as scatterplots, interactive Plotly graphs, and county-level maps, the study identifies patterns and trends between education and income. The results help highlight differences among Tennessee counties and provide insight into how educational attainment may be associated with economic opportunities and financial well-being. Overall, the analysis demonstrates how publicly available Census data can be used to better understand socioeconomic conditions across the state.
## `geom_smooth()` using formula = 'y ~ x'
Code:
############################################################
# FINAL PROJECT
# Educational Attainment and Median Household Income
# Tennessee Counties
############################################################
# ==========================
# STEP 1: LOAD PACKAGES
# ==========================
library(tidyverse)
library(tidycensus)
library(tigris)
library(sf)
library(plotly)
library(leaflet)
library(scales)
library(htmltools)
tn_data <- read_csv(
"TN_Education_Income_Project.csv"
)
tn_data <- tn_data %>%
mutate(
GEOID = as.character(GEOID)
)
names(tn_data)
glimpse(tn_data)
# ==========================
# STEP 6: SUMMARY STATS
# ==========================
summary(tn_data)
mean(
tn_data$median_income,
na.rm = TRUE
)
mean(
tn_data$pct_bachelors_plus,
na.rm = TRUE
)
# ==========================
# STEP 7: CORRELATION
# ==========================
correlation <- cor(
tn_data$median_income,
tn_data$pct_bachelors_plus,
use = "complete.obs"
)
correlation
# ==========================
# STEP 8: REGRESSION MODEL
# ==========================
model <- lm(
median_income ~ pct_bachelors_plus,
data = tn_data
)
summary(model)
# ==========================
# STEP 9: SCATTERPLOT
# ==========================
scatter_plot <- ggplot(
tn_data,
aes(
x = pct_bachelors_plus,
y = median_income
)
) +
geom_point(
color = "steelblue",
size = 3
) +
geom_smooth(
method = "lm",
color = "red"
) +
scale_y_continuous(
labels = dollar
) +
labs(
title =
"Educational Attainment and Income in Tennessee Counties",
x =
"Percent of Adults with Bachelor's Degree or Higher",
y =
"Median Household Income"
) +
theme_minimal()
scatter_plot
# ==========================
# STEP 10: INTERACTIVE LEAFLET MAP
# ==========================
# Tennessee County Boundaries
tn_map <- counties(
state = "TN",
cb = TRUE,
year = 2023
)
# Join Census Data
map_data <- left_join(
tn_map,
tn_data,
by = "GEOID"
)
# Check Join Worked
summary(map_data$median_income)
# Create Palette
pal <- colorNumeric(
palette = "YlGnBu",
domain = map_data$median_income,
na.color = "gray"
)
# Create Interactive Map
county_map <- leaflet(map_data) %>%
addTiles() %>%
addPolygons(
fillColor = ~pal(median_income),
fillOpacity = 0.8,
color = "white",
weight = 1,
label = ~paste0(
dollar(median_income)
)
) %>%
addLegend(
pal = pal,
values = ~median_income,
title = "Median Household Income",
position = "bottomright"
)
county_map
# ==========================
# STEP 11: INTERACTIVE PLOTLY
# ==========================
plotly_graph <- ggplot(
tn_data,
aes(
x = pct_bachelors_plus,
y = median_income,
text = paste(
"<b>", variable, "</b>",
"<br>Education:",
round(pct_bachelors_plus, 1), "%",
"<br>Income:",
dollar(median_income)
)
)
) +
geom_point(
color = "darkgreen",
size = 3
) +
geom_smooth(
method = "lm",
color = "orange",
se = FALSE
) +
theme_minimal()
interactive_plot <- ggplotly(
plotly_graph,
tooltip = "text"
)
interactive_plot