Created
March 5, 2021 05:03
-
-
Save arvi1000/1172ad257d38ac52e77bfd0f8c874187 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
94720
94502
94606
94704
94708
94605
94618
94611
94609
94603
94546
94501
94607
94563
94608
94619
94621
94702
94703
94577
94705
94602
94601
94610