Census - Example - census

Data - Census

  lib_dir: libs self_contained: false bookdown::pdf_document2: citation_package: natbib number_sections: false fig_caption: yes toc: no —

~/data/census/

Tract-Level Maps: Los Angeles County

ACS 5

Code
variable.list.acs.2016 <- load_variables(2016, "acs5", cache = FALSE)

variable.list.acs.2016 |>
  filter(grepl("Share of Aggregate Income", label))
# # A tibble: 5 × 4
#   name       label                                             concept geography
#   <chr>      <chr>                                             <chr>   <chr>    
# 1 B19082_001 Estimate!!Quintile Share of Aggregate Income!!Lo… SHARES… tract    
# 2 B19082_002 Estimate!!Quintile Share of Aggregate Income!!Se… SHARES… tract    
# 3 B19082_003 Estimate!!Quintile Share of Aggregate Income!!Th… SHARES… tract    
# 4 B19082_004 Estimate!!Quintile Share of Aggregate Income!!Fo… SHARES… tract    
# 5 B19082_005 Estimate!!Quintile Share of Aggregate Income!!Hi… SHARES… tract

Decennial census

Code
variable.list.sf1 <- load_variables(2010, "sf1", cache = FALSE)

variable.list.sf1 |>
  filter(grepl("Income", concept))
# # A tibble: 0 × 3
# # ℹ 3 variables: name <chr>, label <chr>, concept <chr>
Code
# get_decennial(year = 1990) : endpoint 1990 supprime par le Census Bureau
# (annees valides : 2000, 2010, 2020) ; m90.county n'etait pas utilise ensuite.

Median Monthly Housing Costs

Code
options(tigris_use_cache = TRUE)
la <- get_acs(state = "CA", county = "Los Angeles", geography = "tract", 
              variables = "B25105_001", geometry = TRUE) |>
  rename(median_housing_costs = estimate)

mapview(la, zcol = "median_housing_costs", legend = TRUE)

Median Income

Code
options(tigris_use_cache = TRUE)
la <- get_acs(state = "CA", county = "Los Angeles", geography = "tract", 
              variables = "B19013_001", geometry = TRUE) |>
  rename(median_income = estimate)

mapview(la, zcol = "median_income", legend = TRUE)

2000 Median Rent

Code
options(tigris_use_cache = TRUE)
la <- get_decennial(state = "CA", county = "Los Angeles", geography = "tract",
                    variables = "H063001", year = 2000, geometry = TRUE) |>
  rename(median_rent = value)

mapview(la, zcol = "median_rent", legend = TRUE)

2013-2017 Median Rent

Code
options(tigris_use_cache = TRUE)
la <- get_acs(state = "CA", county = "Los Angeles", geography = "tract",
                    variables = "B25064_001", geometry = TRUE) |>
  rename(median_rent = estimate)

mapview(la, zcol = "median_rent", legend = TRUE)

Tract-level: Others

Orange County

Code
options(tigris_use_cache = TRUE)
orange <- get_acs(state = "CA", county = "Orange", geography = "tract", 
              variables = "B19013_001", geometry = TRUE)

mapview(orange, zcol = "estimate", legend = TRUE)

Santa Barbara County

Code
options(tigris_use_cache = TRUE)
santa_barbara <- get_acs(state = "CA", county = "Santa Barbara", geography = "tract", 
              variables = "B19013_001", geometry = TRUE)

mapview(santa_barbara, zcol = "estimate", legend = TRUE)

San Francisco County

Code
options(tigris_use_cache = TRUE)
san_francisco <- get_acs(state = "CA", county = "San Francisco", geography = "tract", 
              variables = "B19013_001", geometry = TRUE)

mapview(san_francisco, zcol = "estimate", legend = TRUE)

County-Level Maps

Median Income: 2013-2017 ACS

(ref:county-median-income) Median Income by County (Source: 2013-2017 ACS)

Code
get_acs(geography = "county", variables = "B19013_001") |>
  mutate(region = GEOID |> as.numeric()) |>
  select(region, value = estimate) |>
  mutate(value = case_when(value < 30000 ~ "< $30K",
                           value >= 30000 & value < 40000 ~ "$30K to $40K",
                           value >= 40000 & value < 50000 ~ "$40K to $50K",
                           value >= 50000 & value < 60000 ~ "$50K to $60K",
                           value >= 60000 & value < 70000 ~ "$60K to $70K",
                           value >= 70000 ~ "$70K+")) |>
  county_choropleth()

(ref:county-median-income)

2000 Median Rents

To plot our first map, we use 2000 census county-level data on median rents. First, load tidycensus as well as choroplethr. Second, get a key for the Census API here, input it to census_key, and run the following in a R chunk:

Code
census_api_key(census_key)

Finally, plot median rents by county in the 2000 Census:

(ref:county-rents-census-2000) Census-Level Median Rent (Source: 2000 Census)

Code
get_decennial(geography = "county", variables = "H063001", year = 2000) |>
  mutate(region = GEOID |> as.numeric()) |>
  mutate(value = case_when(value < 200 ~ "$0 to $200",
                           value >= 200 & value < 300 ~ "$200 to $300",
                           value >= 300 & value < 400 ~ "$300 to $400",
                           value >= 400 & value < 600 ~ "$400 to $600",
                           value >= 600 & value < 800 ~ "$600 to $800",
                           value >= 800 ~ "$800+")) |>
  county_choropleth()

(ref:county-rents-census-2000)