Skip to content

Instantly share code, notes, and snippets.

@pumphandle
pumphandle / choropleth1.r
Created August 5, 2019 19:26
Makes a simple choropleth map using custom shapefile
library(tidycensus)
library(tidyverse)
library(rgdal)
census_api_key("<your api key here>", overwrite=T, install="TRUE")
uspop <- get_acs(geography = "state", variables = c(pop = "B06012_001"), year=2017)
uspov <- get_acs(geography = "state", variables = c(pov="B06012_002"), year=2017)
uspovrate <- uspov$estimate/uspop$estimate
us <- cbind(uspop, uspovrate)
@pumphandle
pumphandle / distance_to_coast.R
Created July 12, 2019 19:00
Finds distance to nearest shoreline in the continental US
library(rgdal)
library(geosphere)
coast <- readOGR(dsn="shapefile path", layer="us_medium_shoreline")
dist2Line(c(-85,32),coast,distfun=distGeo)
@pumphandle
pumphandle / tidycensus1.r
Created July 9, 2019 17:46
Read in ACS block group populations for New York State
library(tidycensus)
census_api_key("your api key here", install=TRUE)
ny <- get_acs(geography = "block group", variables = c(population = "B01003_001"), state="NY")