This is a walkthrough of the material at https://walkerke.github.io/tidycensus/articles/basic-usage.html

First get a census api key and load the required libraries. Make sure that you have tidycensus and viridis installed on your computer.

library(tidyverse)
## ── Attaching packages ─────────────────
## ✔ ggplot2 3.0.0     ✔ purrr   0.2.5
## ✔ tibble  1.4.2     ✔ dplyr   0.7.6
## ✔ tidyr   0.8.1     ✔ stringr 1.3.1
## ✔ readr   1.1.1     ✔ forcats 0.3.0
## ── Conflicts ──────────────────────────
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(tidycensus)
library(viridis)
## Loading required package: viridisLite
#census_api_key("e86c386d15a50c2981a55346f28b3d13e3036da6")

Get the median gross rent by state from the 1990 decennial census.

m90 <- get_decennial(geography = "state", variables = "H043A001", year = 1990)
## Getting data from the 1990 decennial Census
head(m90)

Do Walker’s graph. Play with fig.width and fig.height in the R chunk spec to get something readable.

m90 %>%
  ggplot(aes(x = value, y = reorder(NAME, value))) + 
  geom_point()

The statistical data is not in the decennial data after 1990. We have to use the most recent 5-year acs data.

Let’s get the list of variables for the most recent acs.

v16 <- load_variables(2016, "acs5", cache = TRUE)
head(v16)
str(v16)
## Classes 'tbl_df', 'tbl' and 'data.frame':    22815 obs. of  3 variables:
##  $ name   : chr  "B00001_001" "B00002_001" "B01001_001" "B01001_002" ...
##  $ label  : chr  "Estimate!!Total" "Estimate!!Total" "Estimate!!Total" "Estimate!!Total!!Male" ...
##  $ concept: chr  "UNWEIGHTED SAMPLE COUNT OF THE POPULATION" "UNWEIGHTED SAMPLE HOUSING UNITS" "SEX BY AGE" "SEX BY AGE" ...

Look at v16 in View. Look at American Factfinder and ACS manual.

ACS

Let’s get the most recent 5-year ACS variables.

v16 <- load_variables(2016, "acs5", cache = TRUE)
str(v16)
## Classes 'tbl_df', 'tbl' and 'data.frame':    22815 obs. of  3 variables:
##  $ name   : chr  "B00001_001" "B00002_001" "B01001_001" "B01001_002" ...
##  $ label  : chr  "Estimate!!Total" "Estimate!!Total" "Estimate!!Total" "Estimate!!Total!!Male" ...
##  $ concept: chr  "UNWEIGHTED SAMPLE COUNT OF THE POPULATION" "UNWEIGHTED SAMPLE HOUSING UNITS" "SEX BY AGE" "SEX BY AGE" ...

Median Income

Walker’s Vermont Example - Change to WA

wa <- get_acs(geography = "county", 
              variables = c(medincome = "B19013_001"), 
              state = "WA")
## Getting data from the 2012-2016 5-year ACS
wa