The purpose of this project was to examine the relationship between educational attainment and median household income across Tennessee counties. Specifically, the project explored whether counties with higher percentages of adults holding a bachelor’s degree or higher also tend to have higher median household incomes. Education is often associated with greater employment opportunities and earning potential, making it an important factor when examining economic conditions. By focusing on Tennessee counties, the project provides a clearer understanding of how education and income vary throughout the state and whether these two variables appear to be related.
The data used in this project originated from the American Community Survey (ACS), which is produced by the U.S. Census Bureau. The ACS provides demographic, social, economic, and housing information for geographic areas across the United States. County-level data were obtained through the Census API and processed using the tidycensus package in R.
The final dataset included information for all 95 Tennessee counties and contained variables such as county identifier (GEOID), median household income, and the percentage of adults with a bachelor’s degree or higher. After the data were collected and cleaned, the dataset was saved as a CSV file and imported into the project for analysis and visualization.
The completed project produced several outputs that help explain the relationship between educational attainment and income in Tennessee.
The first output was a scatterplot that displayed educational attainment on the x-axis and median household income on the y-axis. This visualization provided a clear view of the relationship between the two variables and included a regression line to show the overall trend.The second output was an interactive Plotly visualization. This graph allowed users to hover over individual data points and view additional information about each county. Interactive graphics make it easier to explore the data and identify specific counties that differ from overall patterns.
The third output was an interactive Leaflet choropleth map that displayed county-level income data across Tennessee. The map allowed users to interact with counties and view income information geographically, making it easier to identify regional patterns.The final output was a bar chart displaying the top ten Tennessee counties with the highest median household incomes. This chart highlighted counties that ranked highest economically and provided another way to summarize the data.
Although artificial intelligence was used to assist with coding and troubleshooting, I completed several important aspects of the project independently. I selected the research topic, developed the research question, identified the variables that would be analyzed, and determined that Tennessee counties would serve as the unit of analysis. I reviewed the outputs generated during the project, interpreted the visualizations, and evaluated whether the results were reasonable and accurately represented the data.
I also spent significant time debugging the project and correcting errors. Throughout the development process, I encountered issues involving Census API calls, object naming inconsistencies, county identifiers, Plotly visualizations, and Leaflet mapping. Resolving these issues required testing code, reviewing error messages, making corrections, and ensuring that the final outputs were generated successfully.
Artificial intelligence was used primarily as a coding assistant and troubleshooting resource. AI helped generate examples of R code, suggest improvements to visualizations, explain error messages, and recommend methods for producing interactive maps and graphs. AI also provided guidance for combining datasets and creating visualizations using ggplot2, Plotly, and Leaflet.
While AI assisted with the technical implementation of the project, I remained responsible for selecting the project topic, determining the analytical goals, reviewing the code, verifying the outputs, and integrating the various project components into a final report.
One of the most important lessons from this project was learning how different sources of public data can be accessed and analyzed through R. I became more familiar with working with Census data and gained additional experience cleaning, organizing, and visualizing datasets.
I also learned the importance of troubleshooting and debugging code. Many errors resulted from variable naming inconsistencies, missing objects, incorrect joins, and formatting issues. Working through these challenges improved my understanding of how R processes data and how different packages interact with one another.
The project begins by loading the necessary R packages, including tidyverse, tidycensus, tigris, sf, plotly, leaflet, scales, and htmltools. These packages provide functionality for data acquisition, management, visualization, mapping, and formatting.
Next, the CSV dataset containing Tennessee county data is imported into R. The GEOID variable is converted to character format to ensure compatibility when merging geographic boundary data with county-level Census data.
Descriptive statistics are then calculated to summarize the dataset. These calculations include averages and general summaries of educational attainment and median household income.
A correlation analysis is performed to measure the strength of the relationship between educational attainment and income. This provides a numerical estimate of how strongly the two variables are associated.
A linear regression model is then created to further evaluate the relationship between educational attainment and median household income. The regression output helps determine whether educational attainment serves as a useful predictor of income levels across counties.
The next section generates a scatterplot using ggplot2. Each point represents a Tennessee county, and a regression line is added to illustrate overall trends in the data.
The Plotly section converts the scatterplot into an interactive graph. Users can hover over data points to view additional details, making it easier to examine individual counties.
The Leaflet section creates an interactive choropleth map using county boundary data from the tigris package. County income values are joined to the geographic data, color-coded according to income levels, and displayed on an interactive map.
Finally, a bar chart is generated showing the top ten Tennessee counties with the highest median household incomes. This visualization provides a simple and effective summary of the counties that rank highest economically.
This project successfully examined the relationship between educational attainment and median household income across Tennessee counties using data obtained from the American Community Survey. Through statistical analysis, mapping, and visualization, the project demonstrated how publicly available data can be used to explore socioeconomic patterns at the county level. In addition to providing insight into Tennessee communities, the project strengthened my skills in data acquisition, visualization, statistical analysis, mapping, and troubleshooting in R.
############################################################
# 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