The interactive map displays the percentage of working individuals in the labor force in Davidson sub counties that do not have health insurance. In some areas, almost a third of these individuals have no health insurance, highlighting the rising insurance crisis in Tennessee.

Code:

library(tidyverse)
library(tidycensus)
library(sf)
library(mapview)
library(leaflet)
library(leafpop)


# Transmitting API key

census_api_key("35989942993f23ba972685ee05578b3cdb4636bb")

# Specifying target variables

VariableList = 
  c(Estimate_ = "DP03_0108P")

# Fetching data

mydata <- get_acs(
  geography = "county subdivision",
  state = "TN",
  variables = VariableList,
  year = 2023,
  survey = "acs5",
  output = "wide",
  geometry = TRUE,
  )

# Reformatting data

mydata <-
  separate_wider_delim(mydata,
                       NAME,
                       delim = ", ",
                       names = c("Division", "County", "State"))

filtereddata <- mydata %>% 
  filter(County %in% c("Davidson County"))

# Plotting data

mygraph <- ggplot(filtereddata, aes(x = Estimate_E, y = reorder(Division, Estimate_E))) + 
  geom_errorbarh(aes(xmin = Estimate_E - Estimate_M, xmax = Estimate_E + Estimate_M)) + 
  geom_point(size = 3, color = "#099d91") + 
  theme_minimal(base_size = 12.5) +
  labs(title = "Estimates by area", 
       subtitle = "County subdivisions. Brackets show error margins.", 
       x = "2019-2023 ACS estimate", 
       y = "")

mygraph

# Mapping data

mapdata <- filtereddata %>% 
  rename(Estimate = Estimate_E,
         Range = Estimate_M)

mapdata <- st_as_sf(mapdata)

mapviewOptions(basemaps.color.shuffle = FALSE)

DivisionMap <- mapview(mapdata,
                       zcol = "Estimate",
                       layer.name = "Estimate",
                       popup = popupTable(
                         mapdata,
                         feature.id = FALSE,
                         row.numbers = FALSE,
                         zcol = c(
                           "State",
                           "County",
                           "Division",
                           "Estimate",
                           "Range")))

DivisionMap