Get boundaries of zip codes (ZCTA polygons), to analyze or map zip codes
Source:R/shapes_from_zip.R
shapes_from_zip.RdDownloads Census ZIP Code Tabulation Area (ZCTA) boundaries
for the specified zip code(s), returning polygons that can be analyzed
like any other shapefile, as with ejamit(zipcode = 10605) which uses
this function. See the Zipcodes article/vignette for more background.
Arguments
- zipcode
vector of one or more 5-digit zip codes, as numbers or text (leading zeroes are restored if missing, so 1001 means zip code 01001, and a ZIP+4 like "10605-1234" is truncated to its first 5 digits)
- year
optional year of ZCTA vintage, passed to
tigris::zctas(). If NULL (default), the tigris package default is used.- ...
passed to
tigris::zctas()
Value
A spatial data.frame (sf::sf) with one row per zip code found
(in the same order as the requested zip codes), including a zip column.
Details
Census uses ZIP Code Tabulation Areas (ZCTAs), which are
generalized areal representations of United States Postal Service (USPS)
ZIP Code service areas – see help("zctas", package = "tigris").
Some zip codes (e.g., ones used only for PO boxes or single buildings)
have no ZCTA polygon, and this function warns about and drops those.
Note the first use can be slow, since tigris::zctas() downloads a large
national file, but it is cached locally (see tigris::tigris_cache_dir())
so later calls are fast.