US Census Spatial Data

US Census spatial data sandbox

Part 1

Run the code below to compare various legal and US Census geographies. Then, consider the following questions:

  1. To what do boundaries coincide (E.g., MSAs align with what?)?
  2. Do any geographies seem malformed or weirdly shaped?
  3. How many block groups are there per tract?
  4. Does anything surprise you?
library(tigris)
library(leaflet)
library(dplyr)
library(sf)

ec_block_groups <- block_groups(state = "55", county = "Eau Claire")
ec_census_tracts <- tracts(state = "55", county = "Eau Claire")

cbsa <- core_based_statistical_areas(year=2020)
csa <- combined_statistical_areas(year=2020)

leaflet() %>%
  addProviderTiles(provider = providers$CartoDB.Positron) %>%
  addPolygons(data = ec_block_groups, group = "Block Groups", fillColor = "yellow", label = ~NAMELSAD, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addPolygons(data = ec_census_tracts, group = "Tracts", fillColor = "blue", label = ~NAMELSAD, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addPolygons(data = cbsa, group = "CBSA", fillColor = "green", label = ~NAMELSAD, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addPolygons(data = csa, group = "CSA", fillColor = "red", label = ~NAMELSAD, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addLayersControl(overlayGroups = c("Block Groups", "Tracts", "CBSA", "CSA"))

Part 2

Run the code below to compare place (i.e. municipality) boundaries to US Census Urban Areas:

library(sf)
library(tigris)
library(leaflet)
library(dplyr)

wi_counties <- counties("55")
wi_places <- places("55")

wi_urban <- urban_areas() %>%
  st_intersection(., wi_counties)

leaflet() %>%
  addProviderTiles(provider = providers$CartoDB.Positron) %>%
  addPolygons(data = wi_counties, group = "Counties", fillColor = "cyan", label = ~NAME, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addPolygons(data = wi_places, group = "Places", fillColor = "magenta", label = ~NAME, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addPolygons(data = wi_urban, group = "Urban Areas", fillColor = "yellow", label = ~NAME10, weight = 1, smoothFactor = 0.5, color = "#444444") %>%
  addLayersControl(overlayGroups = c("Counties", "Places", "Urban Areas"))