Learn R Programming

choroplethr (version 1.7.0)

choroplethr: Create a choropleth

Description

Creates a choropleth from a specified data.frame and level of detail.

Usage

choroplethr(df, lod, num_buckets = 9, title = "", scaleName = "",
  showLabels = TRUE, states = state.abb, renderAsInsets = TRUE,
  warn_na = TRUE, countries = NULL)

Arguments

df
A data.frame with a column named "region" and a column named "value". If lod is "state" then region must contain state names (e.g. "California" or "CA"). If lod is "county" then region must contain county FIPS codes. if lod is "zip" then region must co
lod
A string indicating the level of detail of the map. Must be "state", "county", "zip" or "world".
num_buckets
The number of equally sized buckets to places the values in. A value of 1 will use a continuous scale, and a value in [2, 9] will use that many buckets. For example, 2 will show values above or below the median, and 9 will show the maximum resolution.
title
A title for the map. Defaults to "".
scaleName
An optional label for the legend. Defaults to "".
showLabels
For state choropleths, whether or not to show state abbreviations on the map. Defaults to T.
states
A vector of states to render. Defaults to state.abb.
renderAsInsets
If true, Alaska and Hawaii will be rendered as insets on the map. If false, all 50 states will be rendered on the same longitude and latitude map to scale. This variable is only checked when the "states" variable is equal to all 50 states.
warn_na
If true, choroplethr will emit a warning when it renders a state or county as an NA.
countries
If null, render all countries. Otherwise must be a vector of country names. See ?country.names for a list of valid country names.

Value

  • A choropleth.

See Also

choroplethr_acs which generates choropleths from Census tables.

Examples

Run this code
data(choroplethr)

# 2012 US Presidential results
choroplethr(df_president, lod="state", title="2012 US Presidential Results")

# 2012 state population estimates - continuous vs. discrete scale
choroplethr(df_pop_state, lod="state", num_buckets=1, title="2012 State Population Estimates")
choroplethr(df_pop_state, lod="state", num_buckets=9, title="2012 State Population Estimates")

# West coast counties in 2012 which were above or below the median population
choroplethr(df_pop_county, lod="county", num_buckets=2,
title="2012 County Population Estimates", states=c("CA", "OR", "WA"))

# Zip Code Tabulated Area (ZCTA) population estimates.
choroplethr(df_pop_zip, "zip", title="2012 Population of each ZIP Code Tabulated Area (ZCTA)")

Run the code above in your browser using DataLab