Created
May 9, 2018 18:44
-
-
Save mfherman/ba538bb7e766c529d8402b1f8f539d48 to your computer and use it in GitHub Desktop.
sf point in polygon
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
library(tidyverse) | |
library(tidycensus) | |
library(sf) | |
library(tmap) | |
options(tigris_use_cache = TRUE) | |
sro <- read_csv("https://github.com/mfherman/r-study-group/raw/master/nyc_sro.csv") | |
sro_sf <- sro %>% | |
st_as_sf(coords = c("lon", "lat")) %>% | |
st_set_crs(4326) | |
# download acs 5 year estimates by county | |
nyc_tract <- get_acs( | |
geography = "tract", | |
state = "NY", | |
county = c("Kings", "Queens", "Bronx", "New York", "Richmond"), | |
variables = "B19013_001", | |
survey = "acs5", | |
year = 2016, | |
geometry = TRUE | |
) %>% | |
st_transform(4326) | |
sro_tract <- st_join(sro_sf, nyc_tract, join = st_within) | |
tmap_mode("view") | |
tm_shape(nyc_tract) + | |
tm_fill( | |
col = "estimate", | |
n = 5, | |
style = "jenks", | |
title = "Median HH Income" | |
) + | |
tm_shape(sro_tract) + | |
tm_dots() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment