Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3....

25
Variables and Vintages Ari Lamstein

Transcript of Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3....

Page 1: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Variables and VintagesAri Lamstein

Page 2: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Course Outline

1. Introduction

2. Choroplethr Basics

3. Variables and Vintages

4. Data Details

5. Learning More

Page 3: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Variables and Vintages

• More variables

• More years

• Calculating percent change

• Mapping percent change

Page 4: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

?df_state_demographics

Page 5: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

data(df_state_demographics) View(df_state_demographics)

Page 6: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

How to map?

Page 7: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

df_state_demographics$value = df_state_demographics$per_capita_income

Page 8: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

View(df_state_demographics)

Page 9: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

state_choropleth(df_state_demographics, num_colors = 2, title = "2013 State Per Capita Income Estimates", legend = "Dollars")

Page 10: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Module Outline

• More variables

• More years

• Calculating percent change

• Mapping percent change

Page 11: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

https://api.census.gov/data/key_signup.html

API Keys

https://api.census.gov/data/key_signup.html

Page 12: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Set your keyOnly need to do this once

Page 13: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

?get_state_demographics

Page 14: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

df_2010 = get_state_demographics(2010) View(df_2010)

Does this look familiar?

Page 15: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

df_2010$value = df_2010$per_capita_income state_choropleth(df_2010)

Page 16: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

df_2015 = get_state_demographics(2015) df_2015$value = df_2015$per_capita_income

state_choropleth(df_2015)

Page 17: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Module Outline

• More variables

• More years

• Calculating percent change

• Mapping percent change

Page 18: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

?calculate_percent_change

Page 19: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

df_change = calculate_percent_change(df_2010, df_2015) View(df_change)

Page 20: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

df_change = df_change[, c("region", "value.x", "value.y", "value")]

View(df_change)

Remove unnecessary columns (optional)

Page 21: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Module Outline

• More variables

• More years

• Calculating percent change

• Mapping percent change

Page 22: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

state_choropleth(df_change)

Page 23: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

state_choropleth(df_change, num_colors=0)

Page 24: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

state_choropleth(df_change, num_colors=0, title = "Percent Change in Estimated Per-Capita Income, 2010-2015”, legend=“Percent")

Page 25: Variables and Vintages · 2019-05-10 · Course Outline 1. Introduction 2. Choroplethr Basics 3. Variables and Vintages 4. Data Details 5. Learning More

Module Outline

• More variables

• More years

• Calculating percent change

• Mapping percent change