earl 2015 - mapping census data in rfiles.meetup.com/1406240/mapping census data.pdf · earl 2015 -...

27
Free course: AriLamstein.com/free-course Mapping Census Data in R Ari Lamstein AriLamstein.com Lamstein Consulting LLC

Upload: others

Post on 19-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Free course: AriLamstein.com/free-course

Mapping Census Data in R

Ari LamsteinAriLamstein.comLamstein Consulting LLC

Page 2: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Getting Started❖ Choropleth Maps

❖ “choroplethr” package

❖ Any shapefile, any data

❖ States, Counties, ZIP Codes

❖ American Community Survey (ACS)

❖ Estimates

❖ acs package

❖ Exploratory Data Analysis

Page 3: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Package Basics

Geography Function Package Location Sample Data Zoom

State state_choropleth choroplethr, choroplethrMaps CRAN

df_pop_state,df_state_demographics state

County county_choroplethchoroplethr,

choroplethrMaps CRANdf_pop_county,

df_county_demographics state, county

ZIP (ZCTA) zip_choropleth choroplethrZip github df_pop_zip, df_zip_demographics

state, county, zip, msa

Page 4: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Mapmaking: Basics

Page 5: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

library(choroplethr)library(choroplethrMaps)

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

Page 6: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

state_choropleth(df_pop_state, title = "2012 State Population Estimates", legend = "Population", num_colors = 1)

Page 7: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

data(df_pop_county)

county_choropleth(df_pop_county, title = "2012 County Population Estimates", legend = "Population")

Page 8: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

county_choropleth(df_pop_county, title = "2012 County Population Estimates", legend = "Population", num_colors = 1)

Page 9: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Demographics: Basics

Page 10: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

data(df_county_demographics)

df_county_demographics$value = df_county_demographics$percent_whitecounty_choropleth(df_county_demographics,

title = "2013 County Percent White Estimates", legend = "Percent White")

Page 11: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$percent_white

county_choropleth(df_county_demographics, title = "2013 County Percent White Estimates", legend = "Percent White", num_colors = 1)

Page 12: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$percent_hispanic

county_choropleth(df_county_demographics, title = "2013 County Percent Hispanic Estimates",

legend = "Percent Hispanic”)

Page 13: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$percent_hispanic

county_choropleth(df_county_demographics, title = "2013 County Percent Hispanic Estimates",

legend = "Percent Hispanic”, num_colors = 1)

Page 14: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$percent_black

county_choropleth(df_county_demographics, title = "2013 County Percent Black Estimates", legend = "Percent Black")

Page 15: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$percent_black

county_choropleth(df_county_demographics, title = "2013 County Percent Black Estimates", legend = "Percent Black”,

num_colors = 1)

Page 16: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$per_capita_income

county_choropleth(df_county_demographics, title = "2013 County Income Estimates",

legend = “Per Capita Income")

Page 17: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

df_county_demographics$value = df_county_demographics$per_capita_income

county_choropleth(df_county_demographics, title = "2013 County Income Estimates",

legend = “Per Capita Income”, num_colors = 1)

Page 18: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Customization

Page 19: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Zoomdf_county_demographics$value = df_county_demographics$median_rent

county_choropleth(df_county_demographics, title = "2013 California County Rent", legend = "Dollars", state_zoom = "california")

Page 20: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Reference Mapdf_county_demographics$value = df_county_demographics$median_rent

county_choropleth(df_county_demographics, title = "2013 California County Rent", legend = "Dollars", state_zoom = "california", reference_map = TRUE)

Page 21: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Case Study

Page 22: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM
Page 23: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM
Page 24: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

How has North Dakota changed?

❖ Wrote Following Up on News Stories with Choroplethr and R

❖ Guest blog post in Revolution Analytics blog, 8/25/15

❖ Accessing historic data is easy

❖ Calculated percent change

Page 25: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM
Page 26: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Accessing Historic Data> df = get_state_demographics(endyear=2013, span=5)

> colnames(df)[1] "region" "total_population" [3] "percent_white" "percent_black" [5] "percent_asian" "percent_hispanic" [7] "per_capita_income" "median_rent" [9] "median_age"

Page 27: earl 2015 - mapping census data in rfiles.meetup.com/1406240/Mapping Census Data.pdf · earl 2015 - mapping census data in r.key Created Date: 10/17/2015 4:49:18 PM

Conclusion

❖ Census data is

❖ powerful and relevant

❖ easy to access and map with choroplethr

❖ Free course: arilamstein.com/free-course

❖ Contact: arilamstein.com/contact