Skip to content

Instantly share code, notes, and snippets.

@mfherman
Created May 9, 2018 18:44
Show Gist options
  • Save mfherman/ba538bb7e766c529d8402b1f8f539d48 to your computer and use it in GitHub Desktop.
Save mfherman/ba538bb7e766c529d8402b1f8f539d48 to your computer and use it in GitHub Desktop.
sf point in polygon
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