Aurelia Moser, Map Scientist, CartoDB Workshop - NICAR Session Link
March 6, 2015, 3:20PM-4:20PM
Find this document here:
- Stackedit:
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> |
# autoloess.R: compute loess metaparameters automatically | |
# Kyle Gorman <[email protected]> | |
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. |
#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]]) | |
} |
#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 |
-- 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: |
# 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 %>% |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ |
Main differences are:
tbl_df
html_session
since the site was rejecting the access (login req'd) w/o itfor
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 :-)pbapply
makes it possible to do the row-binding and left-joining in a single pipeline, which keeps everything in a tbl_df
.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, |