A choropleth map is a thematic map that uses different shades or patterns to represent a variable across geographic regions. It is commonly used in research, economics, social studies, and political science to visualize spatial patterns and trends. For example, choropleth maps are often employed to display data such as population density, unemployment rates, voting patterns, or average income levels in a specific area. Choropleth maps effectively translate complex datasets into visual insights, making them invaluable tools for researchers, policymakers, and analysts in various disciplines.
In research, choropleth maps play a vital role in understanding spatial distributions and correlations. Public health researchers frequently use these maps to study the geographic spread of diseases, vaccination rates, or access to healthcare services (Olsson, 2012). Similarly, environmental scientists rely on choropleth maps to analyze patterns of air pollution, deforestation, or water scarcity across regions. Economists and policymakers use choropleth maps extensively to illustrate disparities in income, employment, or economic development. By visualizing data such as GDP per capita or poverty rates, these maps help identify regions requiring targeted interventions (Brewer & Pickle, 2002). They provide a clear and immediate understanding of economic inequality, enabling better resource allocation and decision-making. In the social and political domains, choropleth maps are indispensable for analyzing voting behaviors, population demographics, or educational attainment levels. Political analysts, for instance, use these maps to depict electoral outcomes by region, revealing voting trends and potential areas of political focus. Sociologists also use them to explore social inequalities or cultural differences between urban and rural communities.
Below are the R codes to create the map displayed at the beginning of this article.
# Clear our R environment:
rm(list = ls())
# Load the some R libraries:
library(ggplot2)
library(dplyr)
library(stringr)
library(viridis) # For using viridis colors and unemp data set.
# Get data for all US counties:
county_df <- map_data("county", projection = "albers", parameters = c(39, 45))
data("unemp") # Use unemp data set provided by viridis package.
# Join the two data sets:
county_df %>% left_join(unemp, by = c("subregion" = "county")) -> county_df
# Make Choropleth Map:
library(showtext)
my_font <- "Lato"
font_add_google(name = my_font, family = my_font)
showtext_auto()
ggplot() +
geom_polygon(data = county_df, aes(long, lat, group = group, fill = rate), colour = alpha("white", 0.1)) +
theme_minimal() +
labs(title = "US Unemployment Rate by County, 2009",
subtitle = "This map shows the latest unemployment rate for each county in the United States.\nThe map updates itself daily and will show the most recent data available.",
caption = "Data Source: U.S Census Bureau|Graphic Design: Nguyen Chi Dung") +
theme(text = element_text(family = my_font)) +
theme(axis.text = element_blank()) +
theme(axis.title = element_blank()) +
theme(panel.grid = element_blank()) +
theme(plot.margin = unit(rep(0.5, 4), "cm")) +
theme(plot.title = element_text(size = 18, color = "grey20")) +
theme(plot.subtitle = element_text(size = 10, color = "grey40")) +
theme(plot.caption = element_text(size = 8, color = "grey40")) +
scale_fill_viridis(discrete = FALSE,
option = "A",
name = "Unemployment Rate (%)",
direction = -1,
guide = guide_colourbar(direction = "horizontal",
barheight = unit(2, units = "mm"),
barwidth = unit(40, units = "mm"),
draw.ulim = FALSE,
title.hjust = 0.5,
label.hjust = 0.5,
title.position = "top")) +
theme(legend.position = c(0.5, 0.93)) +
theme(legend.text = element_text(color = "grey30")) +
theme(legend.title = element_text(colour = "grey20", size = 9))
#----------------------------------------------------------------------
# Using tidycensus for retrieving unemployment data from the US Census
#----------------------------------------------------------------------
# We can retrieve updated unemployment data from the US Census as follows:
library(tidycensus)
# Retrieve unemployed and labor force data:
unemployment_data <- get_acs(geography = "county",
variables = c(unemployed = "B23025_005", labor_force = "B23025_003"),
year = 2021,
survey = "acs5")
# Convert to wide form data:
unemployment_data %>%
select(NAME, variable, estimate) %>%
pivot_wider(names_from = "variable", values_from = "estimate") -> unemployment_wide
# Calculate unemployment rate by country:
unemployment_wide %>% mutate(rate = unemployed / labor_force) -> unemployment_wide
#------------------------------------------------------------------------------------------------------
# My Comment: However, to combine this data with geospatial data, additional processing steps may
# be required. For more information about the MAR package, refer to https://walker-data.com/tidycensus/
#-------------------------------------------------------------------------------------------------------