Learn R Programming

choroplethrZip (version 1.5.0)

zip_choropleth: Create a choropleth of US Zip Codes

Description

Note that what is rendered are 2010 US Census Zip Code Tabulated Areas (ZCTAs), not USPS Zip Codes. The map used is zip.map in the choroplethrZip package. See zip.regions for an object which can help you coerce your regions into the required format.

Usage

zip_choropleth(df, title = "", legend = "", num_colors = 7,
  state_zoom = NULL, county_zoom = NULL, msa_zoom = NULL,
  zip_zoom = NULL, reference_map = FALSE)

Arguments

df
A data.frame with a column named "region" and a column named "value". Elements in the "region" column must exactly match how regions are named in the "region" column in ?zip.map.
title
An optional title for the map.
legend
An optional name for the legend.
num_colors
The number of colors on the map. A value of 1 will use a continuous scale. A value in [2, 9] will use that many colors.
state_zoom
An optional vector of State names to zoom in on. Elements of this vector must exactly match the names of the state names as they appear in the "state.name" column of ?zip.regions.
county_zoom
An optional vector of county FIPS codes to zoom in on. Elements of this vector must exactly match the names of zips as they appear in the "county.fips.numeric" column of ?zip.regions.
msa_zoom
An optional vector of MSA (Metroplitan/Micropolitan Statistical Area) names to zoom in on. Elements of this vector must exactly match the names of the state names as they appear in the "cbsa.title" column of ?zip.regions.
zip_zoom
An optional vector of zip codes to zoom in on. Elements of this vector must exactly match the names of zips as they appear in the "region" column of ?zip.regions.
reference_map
If true, render the choropleth over a reference map from Google Maps.

See Also

https://www.census.gov/geo/reference/zctas.html for an explanation of ZCTAs and how they relate to US Zip Codes.

Examples

Run this code
## Not run: ------------------------------------
# 
# library(choroplethrZip)
# data(df_pop_zip)
# 
# # zooming on a state
# zip_choropleth(df_pop_zip,
#                state_zoom = "new york",
#                title      = "2012 New York State ZCTA Population Estimates",
#                legend     = "Population")
# 
# # adding a reference map
# zip_choropleth(df_pop_zip,
#                state_zoom    = "new york",
#                title         = "2012 New York State ZCTA Population Estimates",
#                legend        = "Population",
#                reference_map = TRUE)
# 
# # viewing on a set of counties
# # note we use numeric county FIPS codes
# nyc_fips = c(36005, 36047, 36061, 36081, 36085)
# zip_choropleth(df_pop_zip,
#                county_zoom = nyc_fips,
#                title       = "2012 New York City ZCTA Population Estimates",
#                legend      = "Population")
# 
# # zooming in on a few ZIPs
# manhattan_les = c("10002", "10003", "10009")
# manhattan_ues = c("10021", "10028", "10044", "10128")
# zip_choropleth(df_pop_zip,
#               zip_zoom = c(manhattan_les, manhattan_ues),
#               title    = "2012 Lower and Upper East Side ZCTA Population Estimates",
#               legend   = "Population")
# 
# # zooming in on an entire Metropolitan Statistical Area (MSA)
# zip_choropleth(df_pop_zip,
#                msa_zoom = "New York-Newark-Jersey City, NY-NJ-PA",
#                title    = "2012 NY-Newark-Jersey City MSA\nZCTA Population Estimates",
#                legend   = "Population")
# 
#  # showing the entire country
#  # note: this takes a few minutes to run
#  zip_choropleth(df_pop_zip,
#                title  = "2012 US ZCTA Population Estimates",
#                legend = "Population")
## ---------------------------------------------

Run the code above in your browser using DataLab