Ari Lamstein

New Lesson: Mapping Historic Census Data in R

Today I am happy to announce a new lesson for my free email course Learn to Map Census Data in R. This lesson explains how to get and map historic census data in R. While I had intended this lesson to only go to new signups, it looks like my email provider sent it (along with resending the conclusion email!) to anyone who ever took the course. I apologize for this! For reference, here is the lesson:


Exercise: Map the Population of US States in 2010.

In lesson 2 we used two objects to analyze state demographics:

  1. ?df_pop_state, which has data from the 2012 5-year America Community Survey (ACS)
  2. ?df_state_demographics, which has data from the 2013 5-year ACS

To get data from other years you need to access the US Census API. To do that:

  1. Fill out this form to get a Census API Key. They will email you a key.
  2. When you get your key, type the following in R:

api.key.install("<your key>")


We can now use the function ?get_state_demographics to get data from other surveys. For example, this code will get data from the 2010 5-year ACS:



df_2010_demographics = get_state_demographics(2010)


Creating a map of 2010 population estimates is now simple:


df_2010_demographics$value = 

    title = “2010 State Population Estimates”, 
    legend = “Population”)


Exercise: Make a map showing the Percent Hispanic of Counties in Texas in 2011.


We will get the data with the function ?get_county_demographics, which works analogously to get_state_demographics:


df_2011_demographics = get_county_demographics(2011)

df_2011_demographics$value = 

    title      = "Texas 2011 County\nPercent Hispanic",
    legend     = "Percent Hispanic",
    state_zoom = "texas")


Homework: Use the function ?get_zip_demographics to make a map of some demographic in San Francisco County (FIPS code 6075) in 2011. get_zip_demographics is in the package choroplethrZip. Tweet the resulting image to me (@AriLamstein) with the hashtag #censuscourse.

Ari Lamstein

Ari Lamstein

I currently work as a Staff Data Science Engineer at a marketing analytics consultancy. I have 20 years experience developing software in areas such as data science, web development and video games. I have also worked as a technical trainer and independent consultant.

Thanks for visiting!

Sign up to stay up to date with the latest blog posts: