Skip to content

Instantly share code, notes, and snippets.

@arvi1000
Created March 5, 2021 05:03
Show Gist options
  • Save arvi1000/1172ad257d38ac52e77bfd0f8c874187 to your computer and use it in GitHub Desktop.
Save arvi1000/1172ad257d38ac52e77bfd0f8c874187 to your computer and use it in GitHub Desktop.
options(tigris_use_cache = TRUE)
library(tigris)
library(sf)
# get shapefiles (coarse resolution)
sd_sf <- school_districts(state = 'CA', cb = T)
zip_sf <- zctas(cb=T, state='CA')
# which zips overlap OUSD?
ousd_sf <- sd_sf[grep('Oakland', sd_sf$NAME), ]
oakland_zip_indexes <- which(sapply(st_overlaps(zip_sf, ousd_sf), length) > 0)
ousd_zips <- zip_sf[oakland_zip_indexes, ]
# plot
library(ggplot2)
ggplot() +
geom_sf(data=ousd_zips, color='grey', fill='white', alpha=0.5) +
geom_sf(data=ousd_sf, color='red', fill=NA) +
theme_void()
# print the zips
ousd_zips$ZCTA5CE10
@arvi1000
Copy link
Author

arvi1000 commented Mar 5, 2021

image

94720
94502
94606
94704
94708
94605
94618
94611
94609
94603
94546
94501
94607
94563
94608
94619
94621
94702
94703
94577
94705
94602
94601
94610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment