usmap icon indicating copy to clipboard operation
usmap copied to clipboard

Add support for PUMA geography?

Open ummel opened this issue 2 years ago • 1 comments

Love the package -- great for quick/easy mapping.

Would it be straightforward to add support for Public Use Microdata Area (PUMA) geography?

That would allow for mapping of PUMA-level values derived from American Community Survey microdata files.

ummel avatar Jul 21 '22 02:07 ummel

Thanks! I was unable to find the shape files for these (I think I saw the 2010 version is the latest available with the list of them here: https://www2.census.gov/geo/pdfs/reference/puma/2010_PUMA_Names.pdf).

If you can direct me to where the shape files are located I can look into seeing how difficult it would be incorporate them. I think it will require a potentially significant amount of work since the package is currently only designed to work with FIPS codes whereas these use PUMA5CE codes.

pdil avatar Jul 22 '22 18:07 pdil

Sorry, @pdil . Github never alerted me of your post, so just seeing this!

Probably the easiest way to do this is to ingest the standard Census tract geography/shapefiles and then do a simple merge with the "Census Tract to PUMA Relationship Files" (.txt). That will give you the PUMA boundaries.

So, provided your code can grab and work with the Census tract shapefiles without much effort, getting from there to PUMA's should be straightforward.

ummel avatar Nov 04 '22 00:11 ummel

@ummel, this should be possible now that usmap uses sf-based geometries. Here is some sample code and the output:

#### Load PUMA data from URL
library(dplyr)

# url containing PUMA to FIPS mapping
url <- "https://www2.census.gov/geo/docs/maps-data/data/rel2020/2020_Census_Tract_to_2020_PUMA.txt"

# load data from URL, remove duplicates and irrelevant columns
puma_groups <- readr::read_csv(url) %>%
  mutate(fips = paste0(STATEFP, COUNTYFP), puma = PUMA5CE) %>%
  group_by(fips, puma) %>%
  summarize %>%
  ungroup

#### Combine PUMA data with US map
library(usmap)

counties <- us_map("counties")

us_map_puma <- merge(counties, puma_groups, by = "fips") %>%
  group_by(puma) %>%
  summarize(geometry = sf::st_union(geometry))

#### Plot combined geometries
library(ggplot2)

ggplot() + geom_sf(data = us_map_puma) +
  usmap:::theme_map()

puma-map

How does this look?

pdil avatar Mar 19 '24 17:03 pdil

Looks great. Thank you!

ummel avatar Mar 19 '24 17:03 ummel