census_api_key("put your census api key here", install = TRUE)
Help section
library(tidyverse)library(tidycensus)# look at the help section for the load_variables() function # run the line of code below in your console and look at the help section?load_variables
HELP
List 2020 Census variables
The 2020 Census data release is very delayed from covid
Only data for redistricting is available so far
The 2020 Census Redistricting Data (P.L. 94-171) Summary Files
“pl”
# create table of all variables in the 2020 redistricting filepl_2020 <-load_variables(2020, "pl", cache = T)
Redistricting Race/Ethnicity data
P1. Race
P2. Hispanic or Latino, and Not Hispanic or Latino by Race
P3. Race for the Population 18 Years and Over
P4. Hispanic or Latino, and Not Hispanic or Latino by Race for the Population 18 Years and Over
P5. Group Quarters Population by Major Group Quarters Type
H1. Occupancy Status
Import Housing Units data
housing_units <-get_decennial(geography ="state",variables =c(housing_units ="H1_001N"), year =2020)
GEOID
NAME
variable
value
42
Pennsylvania
housing_units
5742828
06
California
housing_units
14392140
A question:
What percentage of housing units receive an American Community Survey each year?
The answer
# ACS questionaires go to 3.5 million addresses each yearacs_percent <-3500000/sum(housing_units$value)acs_percent
Create a dataframe of estimated Median Household Income and selected race/ethnicity variables for every county in one state. Use this data to understand the relationship between race/ethnicity and income in this state. Explore the dataframe by:
looking at the data
calculating summary statistics
creating plots
Write a paragraph explaining at least 3 things you have learned about your state by exploring the data. Include plots and/or statistics to support your conclusions. (You can upload the plots separately or create a pdf with text and images)
Assignment 6b: specific instructions
Use the get_decennial function to create a dataframe of all counties in one state (pick any state) with the following variables:
GEOID
County
Total Population
Percent Hispanic or Latino
Percent White alone, not Hispanic or Latino
Percent Black alone, not Hispanic or Latino
Percent Asian alone, not Hispanic or Latino
(get more variables if you want!)
Use the get_acs function to create a dataframe of the estimated Median household income all counties in the same state. Use the code below. We’ll learn more about ACS next week.
raw_mhi_2020 =get_acs(geography ="state", variables =c(mhi ="B19013_001"), year =2020)
Join these two dataframes together. Explore as described in the assignment overview.