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(rvest) # web scraping | |
library(dplyr) # data manipulation | |
library(htmlwidgets) # access JavaScript libraries from R | |
library(networkD3) # create D3 network widgets | |
## this script generates an outlink network from Ezra Klein's recent articles | |
# first we build the urls for the most recent 10 pages of klein's archive using sapply and a helper function |
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
# load libraries | |
library(tidyverse) | |
library(rgdal) | |
# get state data | |
states_map <- map_data("state") %>% | |
# use round to create square border | |
mutate_at(.funs = funs(round), .vars = vars(long, lat)) | |
# get park data from https://catalog.data.gov/dataset/national-park-boundariesf0a4c |
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(imager) | |
library(dplyr) | |
library(ggplot2) | |
library(scales) | |
library(TSP) | |
## this function takes a 3 channel image and turns it into a line drawing | |
# internals of the function are all from here https://github.com/aschinchon/travelling-salesman-portrait | |
tspDraw <- function(raw_img, point_sample_size, line_color, back_color) { |
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
# devtools::install_github("tylermorganwall/rayshader") | |
library(rayshader) | |
library(raster) | |
# Mount Marcy DEM data https://cugir.library.cornell.edu/catalog/cugir-008186 | |
mount_marcy = raster("h47elu.dem") | |
mount_marcy_matrix <- matrix(extract(mount_marcy, extent(mount_marcy), buffer = 1000), | |
nrow = ncol(mount_marcy), | |
ncol = nrow(mount_marcy)) |
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(rvest) # web scraping | |
library(tidyverse) # general data munging | |
library(sf) # spatial functions and stats | |
library(lwgeom) # not 100% sure why, but i needed to load this so `udunits` doesn't throw an error | |
## import data ------------ | |
# import a geojson of assembly district outlines | |
nyc_ad <- st_read("http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/nyad/FeatureServer/0/query?where=1=1&outFields=*&outSR=4326&f=geojson") |
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
# devtools::install_github("tylermorganwall/rayshader") | |
library(rayshader) | |
library(raster) | |
# quick function to extract a matrix from the raw raster | |
matrix_extract <- function(raw_raster) { | |
matrix(raster::extract(raw_raster, extent(raw_raster), buffer = 1000), | |
nrow = ncol(raw_raster), | |
ncol = nrow(raw_raster)) | |
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(sf) | |
library(tigris) | |
# start by picking a state from https://github.com/Microsoft/USBuildingFootprints | |
# WARNING: these files can be pretty big. using arizona for its copious subdivisions and reasoanable 83MB. | |
url_footprint <- "https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Arizona.zip" | |
download.file(url_footprint, "Arizona.zip") | |
unzip("Arizona.zip") |
OlderNewer