usmap
usmap copied to clipboard
Add support for PUMA geography?
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.
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.
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, 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()
How does this look?
Looks great. Thank you!