I would like to calculate the population density for ZIP codes in my state (North Carolina). I am able to extract the ZIP code populations and polygons from the US Census and plot the map of North Carolina using the following code:
library(tidycensus)
geo <- get_acs(geography = 'zcta', # Get zip code-level data
state = 'NC', # for NC
year = 2019, # for 2019
table = 'B01003', # from this US Census table
geometry = TRUE) %>% # and return the geospatial polygons for mapping
dplyr::rename('population' = estimate, 'zipcode' = NAME) %>%
select(-moe) %>%
arrange(zipcode)
p <- tm_shape(geo) +
tm_polygons('population')
p
This maps population by ZIP code. In order to calculate and map the population density by ZIP code, I need the area (in miles or kilometers squared) of each ZIP code polygon. I am struggling to find a way of (a) getting this data from the US Census site, (b) finding it elsewhere, or (c) using the polygon geometry to calculate it.
Any suggestions will be appreciated.