Skip to content

Instantly share code, notes, and snippets.

@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;
}
devtools::install_github("cpsievert/cowsay") # pending PR to sckott/cowsay
say("fortune", fortune=59, by="clippy")
// 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);
// 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);
// 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);
// 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 / json_diff.R
Last active August 29, 2015 14:15
Compare output of plotly::gg2list() in two different versions of plotly
json_diff <- function(x, old_ref = "master", new_ref) {
if (!nchar(Sys.which("json-diff")))
stop("The npm module json-diff is required to see json diffs")
devtools::install_github("ropensci/plotly", ref = old_ref)
old_json <- paste0(old_ref, ".json")
cat_json(x, old_json)
if (missing(new_ref)) {
if (basename(getwd()) != "plotly")
stop("Either set working directory to plotly's R package source or give a GitHub reference to install")
devtools::load_all()

Travis uses --depth=50. If I want to checkout master, am I forced to re-clone here?

cpsievert@Carsons-MacBook-Pro:~$ git clone --branch=carson-travis-hook --depth=50 https://github.com/ropensci/plotly.git
Cloning into 'plotly'...
remote: Counting objects: 2510, done.
remote: Compressing objects: 100% (1253/1253), done.
remote: Total 2510 (delta 1225), reused 2277 (delta 1060), pack-reused 0
Receiving objects: 100% (2510/2510), 26.03 MiB | 1.49 MiB/s, done.
Resolving deltas: 100% (1225/1225), done.
@cpsievert
cpsievert / tourr.R
Last active August 29, 2015 14:16
View the result here (takes a second to load) -- http://bl.ocks.org/cpsievert/raw/c10492a88cce72365a17/
# adapted from https://github.com/rstudio/ggvis/blob/master/demo/tourr.r
library(tourr)
library(animint)
mat <- rescale(as.matrix(flea[1:6]))
tour <- new_tour(mat, grand_tour(), NULL)
tour_dat <- function(step_size) {
step <- tour(step_size)
proj <- center(mat %*% step$proj)
// 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);