Skip to content

Instantly share code, notes, and snippets.

@szimmer
Created August 5, 2020 16:05
Show Gist options
  • Save szimmer/7e6d80b18727705743c8b64acb9b696d to your computer and use it in GitHub Desktop.
Save szimmer/7e6d80b18727705743c8b64acb9b696d to your computer and use it in GitHub Desktop.
Estimating Chinese speaking population in NYC using R/tidycensus
library(tidyverse)
library(tidycensus)
nyc_counties <- c("005", "047", "061", "081", "085")
acsvars <- load_variables(2015, "acs5", cache=TRUE)
options(tigris_use_cache = TRUE)
nyc_tract <- get_acs(geography="tract",
variables=c("B16001_001", "B16001_066", "B16001_067", "B16001_068"),
year=2015,
survey="acs5",
state="36",
county = nyc_counties,
output="wide", geometry = TRUE)
nyc_tract_chinese <- nyc_tract %>%
# filter(B16001_001E>0) %>%
select(GEOID, lang_total=B16001_001E, lang_chinese=B16001_066E, geometry) %>%
mutate(PctChinseSpeaking=lang_chinese/lang_total*100) %>%
arrange(GEOID)
summary(nyc_tract_chinese$PctChinseSpeaking)
nyc_tract_chinese
library(sf)
nyc_tract_chinese %>%
ggplot(aes(fill=PctChinseSpeaking)) +
geom_sf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment