This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devtools::install_github("cpsievert/pitchRx") | |
library(pitchRx) | |
# All game IDs that do not contain "mlb" are included in nonMLBgids | |
# In order to grab non-MLB games, you *have to* use these IDs | |
data(nonMLBgids) | |
# Grab IDs for triple A games on June 1st, 2011 | |
# This post explains more about obtaining game IDs with regular expressions -- | |
# http://baseballwithr.wordpress.com/2014/06/30/pitchrx-meet-openwar-4/ | |
aaa <- nonMLBgids[grepl("2011_06_01_[a-z]{3}aaa_[a-z]{3}aaa", nonMLBgids)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devtools::install_github("cpsievert/pitchRx") | |
library(pitchRx) | |
library(dplyr) | |
dat <- scrape(start = "2013-09-01", end = "2013-09-11", | |
suffix = c("inning/inning_all.xml", "players.xml")) | |
# note that gameday_link can be used as a "game identifier" | |
p.data <- dat$pitch %>% | |
select(des, px, pz, sz_bot, sz_top, pitch_type, gameday_link, num) %>% | |
filter(des %in% c("Called Strike", "Ball")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(animint) | |
p <- ggplot(mtcars, aes(mpg, wt)) + | |
geom_point(colour='grey50', size = 4) + | |
geom_point(aes(colour = cyl)) | |
p2 <- p + facet_wrap(cyl~am, nrow = 3) | |
animint2dir(list(plot = p2), "test") | |
p2a <- p + facet_grid(cyl~am) | |
animint2dir(list(plot = p2a), "test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(pitchRx) | |
data(gids, package = "pitchRx") | |
# Grab gameday identifiers for every Twin's home game in 2012 | |
min.gids <- gids[grepl("2012_[0-9]{2}_[0-9]{2}_[a-z]{6}_minmlb", gids)] | |
urls <- paste0(pitchRx:::gids2urls(min.gids), "/rawboxscore.xml") | |
library(XML2R) | |
obs <- XML2Obs(urls) | |
nms <- names(obs) | |
boxscore <- collapse_obs(obs[grepl("^boxscore$", nms)]) |