Skip to content

Instantly share code, notes, and snippets.

library(pitchRx)
library(colorspace)
vals <- rainbow_hcl(361)
data(pitches)
pitches$spin_dir <- with(pitches, factor(round(spin_dir), levels = seq(0, 360)))
p1 <- strikeFX(pitches, color = "spin_dir", point.alpha = 0.3,
adjust = TRUE, contour = TRUE) + facet_grid(pitch_type ~ stand) +
theme(legend.position = "none") +
scale_colour_manual(values = vals) + coord_equal()
@cpsievert
cpsievert / animint.js
Created May 21, 2014 18:41
My first animint plot
// 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);
library(devtools)
install_github("ramnathv/rCharts")
# This will soon have to be install_github("rOpenSci/gistr"); see convo here https://twitter.com/ramnath_vaidya/status/469160178898989056
library(rCharts)
# set your GitHub username and password
options(github.username = "foo", github.password = "bar")
animint2gist <- function(plot.list, out.dir = tempfile(), json.file = "plot.json", open.blocks = interactive()){
gg2animint(plot.list, out.dir, json.file, open.browser = FALSE)
# use a flat file structure!
@cpsievert
cpsievert / animint.js
Created May 21, 2014 19:40
My first animint plot
// 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 / animint.js
Created May 21, 2014 21:00
My animint plot
// 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 / animint.js
Created May 21, 2014 23:02
My animint plot
// 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);
devtools::install_github("tdhock/animint", ref = "carson-test")
library(animint)
iris$id <- 1:nrow(iris)
viz <- list(petal=ggplot()+
geom_point(aes(Petal.Width, Petal.Length, fill=Species,
clickSelects=id), data=iris),
sepal=ggplot()+
geom_point(aes(Sepal.Width, Sepal.Length, fill=Species,
clickSelects=id), data=iris))
dat <- data.frame(x = 1:5, y = 1:5, p = 1:5, q = factor(1:5),
r = factor(1:5))
p <- ggplot(dat, aes(x, y, colour = p, size = q, shape = r)) + geom_point()
p + scale_colour_continuous(guide = "colorbar") + guides(colour = "none") #no guide
p + scale_colour_continuous(guide = "none") + guides(colour = guide_colorbar()) #guide
@cpsievert
cpsievert / animint.js
Last active August 29, 2015 14:02
My animint plot
// Define functions to render linked interactive plots using d3.
// Another script should define e.g.
// <script>
// var plot = new animint("#plot","plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {
var element = d3.select(to_select);
this.element = element;
var Widgets = {};
@cpsievert
cpsievert / update.R
Last active August 29, 2015 14:02
Script to update a PITCHf/x database
library(dplyr)
library(pitchRx)
# This script requires pitchRx 1.5
if (packageVersion("pitchRx") < 1.5) { devtools::install_github("cpsievert/pitchRx"); library(pitchRx) }
# Be sure to specify the *entire* path to your database
db.file <- "~/pitchfx/pitchRx.sqlite3"
stopifnot(file.exists(db.file))
db <- src_sqlite(db.file)
update_db(db$con)