When working with Census data it is common to want information for all the ZCTAs (ZIP Code Tabulation Areas) in a particular state or county. The Census API, however, only returns ZCTA data for the entire nation, with no metadata on which states and counties each one intersects. This makes it difficult, for example, to create a choropleth map of ZCTAs in a particular county.
zctaCrosswalk solves this problem by packaging the Census Bureau’s 2020 ZCTA-to-County Relationship File (which is available for download, but not via the Census API), and providing functions such as get_zctas_by_county() and get_zctas_by_state(). Here’s an example of using zctaCrosswalk along with tidycensus and tigris to map the Median Household Income of ZCTAs in San Francisco County:
library(zctaCrosswalk) library(tidycensus) library(dplyr) library(mapview) # B19013_001 = median household income all_zctas = get_acs( geography = "zcta", variables = "B19013_001", year = 2021, geometry = TRUE) # 6075 = San Francisco County's FIPS code filtered_zctas = filter(all_zctas, GEOID %in% get_zctas_by_county(6075)) mapview(filtered_zctas, zcol = "estimate", layer.name = "Median Household Income")
Without get_zctas_by_county(), you would have to already know which of the nation’s ~33,000 ZCTAs belong to San Francisco County.
I published zctaCrosswalk to CRAN in April 2023, after encountering this issue myself, and realizing that others would likely benefit from my solution. In July 2026 I transferred maintenance of the package to Brenden Smith. As of August 2026 the package has been downloaded approximately 80,000 times.
Related Blog Posts:
