Another plot is required to select dates via a mouseclick. Here we create a time series of the number of pitches thrown (by pitch_type and pitcher_name) and add transparent vertical bars that one may click on to select different dates:
# track the number of pitches per game (for each pitcher-type combination)
library(dplyr)
n_pitches <- pitches %>% group_by(pitch_type, pitcher_name, date) %>% summarise(count = n()) %>%
mutate(group = paste(pitcher_name, pitch_type, sep = ": ")) %>%
mutate(dated = as.Date(date, format = "%Y_%m_%d")) %>%
data.frame %>% mutate(max_n = max(count))
# time series plot with clickSelects
series <- ggplot() +
geom_line(aes(x = dated, y = count, colour = pitch_type,
linetype = pitcher_name, group = group), data = n_pitches) +
stat_identity(aes(x = dated, y = max_n, clickSelects = date, alpha = 0.2),
geom = "bar", data = n_pitches) + scale_alpha(guide = 'none') +
xlab("") + ylab("Number of pitches") + theme_animint(width = 800, height = 200)
plist2 <- list(strike = strike, strikeDate = strike_date, series = series)