Skip to content

Instantly share code, notes, and snippets.

View tiernanmartin's full-sized avatar

Tiernan Martin tiernanmartin

View GitHub Profile
@tiernanmartin
tiernanmartin / nc-geocode-county-seat-gist.R
Last active April 27, 2018 21:00
Scraping Wikipedia, Geocoding Cities, Joining `sf` objects
library(placement)
library(rvest)
library(janitor)
library(sf)
library(tidyverse)
nc <- read_sf(system.file("shape/nc.shp", package="sf"))
glimpse(nc)
@tiernanmartin
tiernanmartin / rstudio-shortcuts.md
Last active January 28, 2018 18:18
Shortcuts in Rstudio
Outcome Shortcut Options
Zoom to panel and maximize Shift+Ctrl+[1-9] 1 = Source, 2 = Console, 3 = Help, etc.
@tiernanmartin
tiernanmartin / set-osm-cid-bldg.R
Created January 22, 2018 20:08
Get OSM data for the buildings in the Chinatown International District, Seattle, WA
library(sf)
library(osmdata)
library(tidyverse)
library(miscgis)
library(mapview)
# BBOX RESOURCE: http://tools.geofabrik.de/calc/#type=geofabrik_standard&bbox=-122.33,47.595759,-122.311374,47.601725&tab=1&proj=EPSG:4326&places=4
cid_bbox <- c(-122.33, 47.5957, -122.3113, 47.6018)
@tiernanmartin
tiernanmartin / test-sf-download-methods.R
Created December 19, 2017 18:46
A benchmarking comparison of two methods: read_sf(geojson_url) vs. esri2sf(rest_service_url)
# Setup ----
library(rbenchmark)
library(tidyverse)
library(sf)
library(esri2sf)
cols <- c( "elapsed", "relative", "user.self", "sys.self")
geojson_url <- "https://opendata.arcgis.com/datasets/3fdb7c41de8548c5ab5f96cb1ef303e2_446.geojson"
@tiernanmartin
tiernanmartin / sf-join-by-most-area-covered.R
Last active December 3, 2017 00:45
An example of the process required to join objects by most area covered
options(
reprex.advertise = FALSE,
reprex.si = TRUE,
reprex.style = TRUE,
reprex.comment = "##",
reprex.tidyverse_quiet = TRUE
)
reprex({
@tiernanmartin
tiernanmartin / dadu-analysis.R
Last active November 18, 2017 00:48
use Seattle Development Capacity to show impact of DADU policy thresholds
# SETUP ----
library(tidyverse)
library(treemapify)
library(RSocrata)
library(snakecase)
library(forcats)
library(waffle)
library(rcartocolor)
# DATA ----
@tiernanmartin
tiernanmartin / rmarkdown_htmlwidget_arrange.Rmd
Last active September 18, 2016 20:53
An example of showing a desired arrangement for html widgets
---
title: "R Notebook"
output:
pdf_document: default
html_notebook: default
---
###Default Arrangement
```{r, echo=FALSE,message=FALSE}
# devtools::install_github("wch/webshot")
@tiernanmartin
tiernanmartin / leafletProxyInModule.R
Created September 8, 2016 21:34
An example showing `leafletProxy()` incompatibility with the shiny module framework (includes a work-around solution)
library(shiny)
library(leaflet)
library(RColorBrewer)
quakeMapUI <- function(id){
ns <- NS(id)
tagList(
bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
@tiernanmartin
tiernanmartin / quintileCompare.R
Created July 25, 2016 21:16
An example showing a dplyr pipeline for checking for changes in quintile groups
library(grDevices) # boxplot.stats()
library(operator.tools) # %!in% logical operator
library(tmap) # 'metro' data set
library(magrittr) # piping
library(dplyr) # exploratory data analysis verbs
library(purrr) # recursive mapping of functions
library(tibble) # improved version of a data.frame
library(ggplot2) # dot plot
library(ggrepel) # avoid label overlap
@tiernanmartin
tiernanmartin / leafletBug.R
Created March 8, 2016 06:44
An example illustrating a possible bug in the Leaflet package
library(shiny)
library(shinydashboard)
library(leaflet)
header <- dashboardHeader(
title = "Example",
titleWidth = "600px"
)
sidebar <- dashboardSidebar(width = "600px")