Combining Choropleth Maps and Reference Maps in R

Recent updates to my mapping packages now make it easy to combine choropleth maps and reference maps in R. All you have to do is pass the parameter reference_map = TRUE to the existing functions. This should “just work”, regardless of which region you zoom in on or what data you display. The following table shows the affected functions and their packages.

MapFunctionPackage
US Statesstate_choroplethchoroplethr
US Countiescounty_choroplethchoroplethr
US ZIP Codeszip_choroplethchoroplethrZip
California Census Tractsca_tract_choroplethchoroplethrCaCensusTract

If you want to learn more about how to use these packages, sign up for my free email course Learn to Map Census Data in R.

Install the Packages

Here is how to get the version of the packages that have these changes:

[code lang=”r” collapse=”true”]

install.packages("choroplethr")

# install.packages("devtools")
library(devtools)
install_github(‘arilamstein/[email protected]’)
install_github("arilamstein/[email protected]")

[/code]

In my experience reference maps provide the most value when viewing small regions. So let’s start with viewing the smallest geographic unit that my packages support: Census Tracts.

Census Tracts

Consider this choropleth map which shows income estimates of census tracts in Los Angeles county from 2013:

Some natural questions this map raises are “What is that large tract in the northeast?” and “Why is Los Angeles county discontiguous?” Both of these questions can be easily answered by combining the choropleth map with a reference map:

The large tract in the northeast is a forest, and Los Angeles is discontiguous because it has two large islands. Here is the code to create those maps:

[code lang=”r” collapse=”true”]
library(choroplethrCaCensusTract)
data(df_ca_tract_demographics)
df_ca_tract_demographics$value = df_ca_tract_demographics$per_capita

ca_tract_choropleth(df_ca_tract_demographics,
title = "2013 Los Angeles Census Tract\n Per Capita Income",
legend = "Income",
num_colors = 4,
county_zoom = 6037)

ca_tract_choropleth(df_ca_tract_demographics,
title = "2013 Los Angeles Census Tract\n Per Capita Income",
legend = "Income",
num_colors = 4,
county_zoom = 6037,
reference_map = TRUE)
[/code]

ZIP Codes

Consider this choropleth which shows income estimates of Manhattan Zip Code Tabulated Areas (ZCTAs) in 2013:

manhattan-zip-1

Someone not familiar with Manhattan’s geography might wonder what the dark neighborhood on the east is, and what the light neighborhood in the north is. Combining the choropleth map with a reference map answers those questions.

manhattan-zip-2

The low-income neighborhood in the north is Harlem, and the high income neighborhood in the east is the Upper East Side.

Here is the source code to create those maps:

[code lang=”r” collapse=”true”]

library(choroplethrZip)
data(df_zip_demographics)
df_zip_demographics$value = df_zip_demographics$per_capita_income

zip_choropleth(df_zip_demographics,
title = "2013 Manhattan ZIP Code Income Estimates",
legend = "Per Capita Income",
county_zoom = 36061)

zip_choropleth(df_zip_demographics,
title = "2013 Manhattan ZIP Code Income Estimates",
legend = "Per Capita Income",
county_zoom = 36061,
reference_map = TRUE)
[/code]

Counties

Reference maps can also be useful when viewing county choropleths. Consider this map which shows county populations in California:

ca-county-1

A common question when viewing this map is “What is the large, low-population county on the eastern part of the state?” Adding a reference map allows us to easily answer the question:

ca-county-2

The county in question contains Death Valley – the hottest, driest and lowest point in North America.

Here is the code to produce those maps:

[code lang=”r” collapse=”true”]
library(choroplethr)
data(df_pop_county)
county_choropleth(df_pop_county,
title = "2012 California County Population Estimates",
legend = "Population",
state_zoom = "california")

county_choropleth(df_pop_county,
title = "2012 California County Population Estimates",
legend = "Population",
state_zoom = "california",
reference_map = TRUE)

[/code]

States

You can also combine choropleth maps with reference maps at the state level:

state-1state-2

At this time you cannot make reference maps with maps that contain insets, such as maps of the 50 US states. Here is the code to produce those maps:

[code lang=”r” collapse=”true”]
library(choroplethr)
data(df_pop_state)
data(continental_us_states)

state_choropleth(df_pop_state,
title = "2012 State Population Estimates",
legend = "Population",
zoom = continental_us_states)

state_choropleth(df_pop_state,
title = "2012 State Population Estimates",
legend = "Population",
zoom = continental_us_states,
reference_map = TRUE)
[/code]

More Information

If you are curious about how this code works, then look at the function render_with_reference_map. If you have technical questions, the best place to ask is the choroplethr google group.

 

Comments on Combining Choropleth Maps and Reference Maps in R

  1. Thanks for the update Ari. I have been having great fun playing with this package and, in particular, have been exploring the creation of bi-variate choropleths.

    1. Ari Lamstein says:

      Let me know if you come up with anything. I’ve been interested in adding support for bivariate choropleths for a while, but I just haven’t had time to dig into it.

Comments are Closed