New Lesson: Mapping Historic Census Data in R

September 7, 2015
By

(This article was first published on AriLamstein.com » R, and kindly contributed to R-bloggers)

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:


state-2010-pop

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:
library(acs)

api.key.install("")

 

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:

 

library(choroplethr)

?get_state_demographics
df_2010_demographics = get_state_demographics(2010)

 

Creating a map of 2010 population estimates is now simple:

 

df_2010_demographics$value = 
    df_2010_demographics$total_population

state_choropleth(df_2010_demographics,
    title = “2010 State Population Estimates”, 
    legend = “Population”)

state-2010-pop

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 = 
    df_2011_demographics$percent_hispanic

county_choropleth(df_2011_demographics,
    title      = "Texas 2011 CountynPercent Hispanic",
    legend     = "Percent Hispanic",
    state_zoom = "texas")

texas-county-2011-percent-hispanic

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.

LEARN TO MAP CENSUS DATA
Subscribe and get my free email course: Mapping Census Data in R!

100% Privacy. We don’t spam.

The post New Lesson: Mapping Historic Census Data in R appeared first on AriLamstein.com.

To leave a comment for the author, please follow the link and comment on their blog: AriLamstein.com » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)