Thanks to Carsen Sievert’s article I was able to make some first experiences with the animint package, which allows one to create linked, interactive (even animated) web graphics using ggplot2 code.

This short post demonstrates linked plots using data from the pitchRx package. The pitchRx package provides Major League Baseball Advanced Media’s Gamedata. In addition with PITCHf/x 3D animations of the baseball flightpaths can be created. If you click on the bars in the bar chart below, the corresponding start versus end speed scatterplot should change to reflect the current selection. According to Sievert the package fills a void where other similar (and also great) packages like rCharts and ggvis currently fall short. I hopefully can spend more time with the package in the future and apply it to different data.

library(pitchRx)
library(animint)
data(pitches, package = "pitchRx")
pitches$type <- interaction(pitches$pitch_type, pitches$pitcher_name)
counts <- ddply(pitches, c("pitch_type", "pitcher_name", "type"),
                summarise, count = length(px))
viz <- list(bars = ggplot() +
              geom_bar(aes(x = factor(pitch_type), y = count,
                           fill = pitcher_name, clickSelects = type),
                      position = "dodge", stat = "identity", data = counts),
            scatter = ggplot() +
              geom_point(aes(start_speed, end_speed, fill = pitcher_name, showSelected = type),
                         alpha = 0.65, data = pitches))
gg2animint(viz)

References



Published

15 May 2014

Tags