Skip to content

Instantly share code, notes, and snippets.

@cpsievert
cpsievert / europe.R
Last active December 1, 2017 23:05 — forked from halhen/europe.R
library(tidyverse)
library(plotly)
# I'm being lazy, please don't do this
# setwd("~/Downloads/Version 2_0_1/")
d <- read_csv('GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') %>%
rbind(read_csv('JRC-GHSL_AIT-grid-POP_1K_2011.csv') %>%
mutate(TOT_P_CON_DT = '')) %>%
mutate(
# devtools::install_github('jalapic/engsoccerdata')
library(engsoccerdata)
library(dplyr)
library(plotly)
library(htmlwidgets)
england$Date <- as.Date(england$Date, format = "%Y-%m-%d")
#Get Data into Format Needed
df<-rbind(
library(jsonlite)
library(tigris)
library(plotly)
library(purrr)
library(tidyr)
library(dplyr)
library(sp)
library(rgeos)
library(rgdal)
library(maptools)
@cpsievert
cpsievert / README.md
Last active July 22, 2018 23:10 — forked from walkerke/README.md
Linked brushing with plotly & leaflet

Shiny app to highlight on a Leaflet map by brushing a Plotly chart. Run for yourself with (provided all of the packages are installed):

shiny::runGist('da941dac84f730adcdde')

To get this to work on another dataset, you're going to need to have a sequential ID variable that matches the pointNumber column in the data frame generated by Plotly's event_data. See the setup.R script for how this was derived.

@cpsievert
cpsievert / shim.R
Created March 8, 2016 05:49 — forked from wch/shim.R
Shim system.file for htmlwidgets so that a dependent package can be used with devtools::load_all()
library(inline)
inc <- '
/* This is taken from envir.c in the R 2.15.1 source
https://github.com/SurajGupta/r-source/blob/master/src/main/envir.c
*/
#define FRAME_LOCK_MASK (1<<14)
#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) & FRAME_LOCK_MASK)
#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) & (~ FRAME_LOCK_MASK))
'
@cpsievert
cpsievert / build-R-devel
Last active March 8, 2016 04:20 — forked from marutter/build-R-devel
A bash script to build r-devel
#!/bin/sh
# This is the location of the source code
cd ~/svn/r-devel/R
# R_PAPERSIZE=letter \
# R_BATCHSAVE="--no-save --no-restore" \
# R_BROWSER=xdg-open \
# PAGER=/usr/bin/pager \
# PERL=/usr/bin/perl \
@cpsievert
cpsievert / parse.retrosheet2.pbp.R
Last active September 4, 2015 19:12 — forked from bayesball/parse.retrosheet2.pbp.R
R function for downloading, upzipping, and appending Retrosheet play-by-play data
parse.retrosheet2.pbp = function(season){
# ADJUSTED FOR MAC -- function will work for WINDOWS and MAC
# download, unzip, append retrosheet data
# assume current directory has a folder download.folder
# download.folder has two subfolders unzipped and zipped
# program cwevent.exe is in unzipped folder (for windows)
download.retrosheet <- function(season){
# get zip file from retrosheet website
download.file(
// Define functions to render linked interactive plots using d3.
// Another script should define e.g.
// <script>
// var plot = new animint("#plot","path/to/plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {
var dirs = json_file.split("/");
dirs.pop(); //if a directory path exists, remove the JSON file from dirs
var element = d3.select(to_select);
@cpsievert
cpsievert / index.html
Last active August 29, 2015 14:14 — forked from MSCAU/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: sans-serif;
font-size: 0.7em;
}