Choosing a Level of Detail (lod)

The main function in the choroplethr package is called choroplethr (?choroplethr). It has two required parameters:

  1. df A data.frame which contains one column named region and one column named value. df can have other columns, too - but choroplethr only cares about these columns.
  2. lod A string which says the geographic level of detail of the data. Must be either state, county or zip.

As the following example shows, the choice of level of detail is important.

State lod

choroplethr comes with a dataset, df_pop_state, which contains 2012 population estimates for US states.

library(choroplethr)
data(choroplethr)

head(df_pop_state)
##       region    value
## 1    Alabama  4777326
## 2     Alaska   711139
## 3    Arizona  6410979
## 4   Arkansas  2916372
## 5 California 37325068
## 6   Colorado  5042853

When calling choroplethr with state level data, region must contain state names (e.g. “California” or “CA”).

choroplethr(df_pop_state, "state", title="2012 State Population Estimates")

plot of chunk unnamed-chunk-2

choroplethr renders state choropleths of the lower 48 states. An optional parameter, showLabels, determines whether to include state abbreviations in the image.

County lod

choroplethr comes with a dataset, df_pop_county, which contains 2012 population estimates for US counties.

head(df_pop_county)
##   region  value
## 1   1001  54590
## 2   1003 183226
## 3   1005  27469
## 4   1007  22769
## 5   1009  57466
## 6   1011  10779

When calling choroplethr with county level data, region must contain county FIPS codes.

choroplethr(df_pop_county, "county", title="2012 County Population Estimates")

plot of chunk unnamed-chunk-4

choroplethr renders county maps with an outline of state boundaries. There are over 3,000 counties in the lower 48 states.

ZIP lod

choroplethr comes with a dataset, df_pop_zip, which contains 2012 population estimates for US ZIP Code Tabulated Areas (ZCTAs). ZCTAs are created and maintained by the US Census Bureau and can be considered approximations of US Postal Codes.

head(df_pop_zip)
##   region value
## 1  00601 18544
## 2  00602 41640
## 3  00603 54540
## 4  00606  6593
## 5  00610 29141
## 6  00612 69017

When calling choroplethr with ZIP level data, region must contain 5 digit ZIP codes.

choroplethr(df_pop_zip, "zip", title="2012 ZIP Code Tabulated Area (ZCTA) Population Estimates")

plot of chunk unnamed-chunk-6

choroplethr renders ZIP level maps as scatterplots. The longitude and latitude of each ZIP code comes from the zipcode package. These are technically not choropleth maps because they do not show the boundaries of the ZIP codes.