# Fun with pitchRx and animint

If you are anything like me, you spend most of the day wrangling data with plyr (or dplyr) and visualizing it with ggplot2. For this reason, I got really excited when I heard about 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. 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. I really want to spend more time with animint since it seems to fill a void where other similar (and also great) packages like rCharts and ggvis currently fall short.

library(pitchRx)
pitches\$type <- with(
pitches,
interaction(pitch_type, pitcher_name)
)
counts <- dplyr::count(pitches, pitch_type, pitcher_name, type)
library(animint)
viz <- list(
bars = ggplot() +
geom_bar(
aes(x = factor(pitch_type),
y = n, fill = pitcher_name,
clickSelects = type),
position = "dodge",
stat = "identity",
data = counts
) + theme(legend.position = "none"),
scatter = ggplot() +
geom_point(
aes(start_speed, end_speed,
fill = pitcher_name, showSelected = type),
alpha = 0.65,
data = pitches)
)
animint2gist(viz)