Skip to content

Instantly share code, notes, and snippets.

View walkerke's full-sized avatar

Kyle Walker walkerke

View GitHub Profile
@wboykinm
wboykinm / index.html
Last active October 13, 2015 18:08
CartoDB Custom Infowindow
<!DOCTYPE html>
<html>
<head>
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
@kylebgorman
kylebgorman / autoloess.R
Last active November 28, 2022 16:06
autoloess.R: set the "span" (smoothing) hyperparameter for a LOESS curve so as to minimize AIC_c (includes a cute demonstration)
# autoloess.R: compute loess metaparameters automatically
# Kyle Gorman <gormanky@ohsu.edu>
aicc.loess <- function(fit) {
# compute AIC_C for a LOESS fit, from:
#
# Hurvich, C.M., Simonoff, J.S., and Tsai, C. L. 1998. Smoothing
# parameter selection in nonparametric regression using an improved
# Akaike Information Criterion. Journal of the Royal Statistical
# Society B 60: 271–293.
@bchartoff
bchartoff / oldfaithful
Created December 10, 2013 22:21
Code to create multi axis plots in Plotly
#combine elements with same name in two named lists (useful for combining layouts)
appendList <- function (x, val)
{
stopifnot(is.list(x), is.list(val))
xnames <- names(x)
for (v in names(val)) {
x[[v]] <- if (v %in% xnames && is.list(x[[v]]) && is.list(val[[v]]))
appendList(x[[v]], val[[v]])
else c(x[[v]], val[[v]])
}
@timelyportfolio
timelyportfolio / code.R
Last active July 9, 2021 18:52
R | Turf.js with V8
#devtools::install("jeroenooms/V8")
library("V8")
library(pipeR)
ct = new_context("window")
# min.js gives me a call stack size error but non-min works fine
ct$source(
"https://raw.githubusercontent.com/morganherlocker/turf/master/turf.js"
)
# one of the examples from turf API docs
@andy-esch
andy-esch / sql.sql
Last active May 7, 2019 17:30
Move Alaska and Hawaii under AZ/NM
-- Convert your states (or other geometries id'd by state) to
-- display as with Alaska, Hawaii, and Puerto Rico transcaled
--
-- @param g: input geometry
-- @param state: column identifying the state (name, postal abbreviation, state FP)
--
-- output: geometries of states in albers projections of the states
--
-- Projections:
@auremoser
auremoser / nicar_15_mappingjs.md
Last active August 29, 2015 14:16
NICAR 15 - Workshop

Mapping JS: Building narrative with geo data + CartoDB

Aurelia Moser, Map Scientist, CartoDB Workshop - NICAR Session Link

March 6, 2015, 3:20PM-4:20PM

Find this document here:

  • Stackedit:
@ramhiser
ramhiser / leaflet-county-explorer.r
Created May 4, 2015 18:25
Leaflet app in R to explore U.S. Census demographics by county
# TODO: Add a Shiny dropdown to select demographic variable
library(leaflet)
library(noncensus)
library(dplyr)
data("counties", package="noncensus")
data("county_polygons", package="noncensus")
data("quick_facts", package="noncensus")
counties <- counties %>%
@RutgerK
RutgerK / Bokeh_test
Last active August 29, 2015 14:21
Bokeh_test
This file has been truncated, but you can view the full file.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [

Main differences are:

  • All the initial data acquisition & munging is kept in one pipeline and the data structure is kept as a tbl_df
  • I ended up having to use html_session since the site was rejecting the access (login req'd) w/o it
  • The for loop is now an apply iteration and pbapply gives you a progress bar for free which is A Good Thing given how long that operation took :-)
  • The move to pbapply makes it possible to do the row-binding and left-joining in a single pipeline, which keeps everything in a tbl_df.
  • Your for solution can be made almost as efficient if you do a img_list <- vector("list", 150) so the list size is pre-allocated.

BTW: the popup code is brilliant and tigris is equally as brilliant!

#' @export
coord_proj <- function(proj="+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
inverse = FALSE, degrees = TRUE,
ellps.default="sphere", xlim = NULL, ylim = NULL) {
try_require("proj4")
coord(
proj = proj,
inverse = inverse,
ellps.default = ellps.default,
degrees = degrees,