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") |
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(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) | |
# 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(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
# 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(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
### make a timeline gif of upcoming elections using data from IFES | |
library(ggplot2) # plotting engine | |
library(dplyr) # data manipulation | |
library(ggrepel) # smart plot labels | |
library(gganimate) # easy gif-making | |
library(lubridate) # dealing with date-time | |
library(RColorBrewer) # color scale |
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
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
"lat","lon","date","date_formatted","details" | |
42.9956397,-71.4547891,"March 24, 2015",2015-03-24,"Manchester, N.H. Kasich gets a taste of New Hampshire folks' vetting of candidates" | |
40.7127837,-74.0059413,"March 25, 2015",2015-03-25,"New York City Conservatives questions Kasich's support of Medicaid expansion in NYC" | |
44.3106241,-69.7794897,"March 25, 2015",2015-03-25,"Augusta, Maine Faber travels to Maine to join Kasich" | |
42.331427,-83.0457538,"April 13, 2015",2015-04-13,"Detroit, Mich. Gov. John Kasich 'seriously considering' running for president" | |
34.8526176,-82.3940104,"April 17, 2015",2015-04-17,"Greenville, S.C. Kasich gets some pushback in South Carolina" | |
42.7653662,-71.467566,"April 18, 2015",2015-04-18,"Nashua, N.H. Kasich shares message, makes friends on the road" | |
38.9071923,-77.0368707,"April 23, 2015",2015-04-23,"Washington, D.C. Kasich, speaking in Washington, discusses potential presidential runSee the video" | |
38.9071923,-77.0368707,"May 1, 2015",2015-05-01,"Washington, D.C. Kasich defends his dire |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>MDIF Portfolio by Freedom House and GNI</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script> | |
<style type = "text/css"> | |
body { | |
background-color: #fff; |
NewerOlder