Let me guess. You love baseball. You’re probably a sabermetrics nerd. You might even keep your own baseball blog. You know about PITCHf/x, but don’t have the resources or computing chops to put it to use. If so, you’re in the right place. PITCHf/x visualization is now easier than ever (and free) thanks to pitchRx and shiny.
A web hosted version of this tool is available here. However, in order to create animations, you’ll need to run the local version. To run the local version, first install R, then enter the following into your R console:
install.packages("shiny")
library(shiny)
shiny::runGitHub('shiny_apps', 'cpsievert', subdir='pitchRx')
This should eventually open your default web browser. Your browser page should look similar to the screenshot below. (I built this using Firefox, if you are running into problems with your browser, please notify me and/or consider using Firefox)
By default, the sample dataset in pitchRx is loaded. However, there is an option to upload any csv file from your local machine (if you don’t have data, but want some, see my post about obtaining PITCHf/x data).
This tool is exciting because you can generate complicated plots quickly and download them for later use (just click the “Download Current Plot” button). I don’t consider myself a baseball analyst, but I would love to see those of you using this work to complement your analyses (please cite pitchRx and/or this post).
Here is a short explanation of what is currently possible with this tool:
First, consider plotting options that apply to any plotting method listed below. These “universal” options include: choosing x-axis and y-axis limits as well as column and/or row-wise facetting.
- Animation of flight paths. Options include choice of different coloring variables.
- Visualization of strikezones. In this case, there are options that apply to any of the four plotting geometries. These options include: adding contour lines to the current plot as well as adjustment of vertical locations according to aggregate strikezones (ie, average heights).
- Using a “point” geometry: Options include choice of different coloring variables.
- Using a “tile” geometry: Options include altering density definitions.
- Using a “hex” geometry: Options include altering density definitions as well as adjustment of hex heights and widths.
- Using a “bin” geometry: Options include altering density definitions as well as adjustment of bin heights and widths.
Altering density definitions is probably my favorite feature. It allows one to examine differences between two different strikezone densities. Since it’s difficult to do this visually, pitchRx provides the basis for plotting differenced densities. For example, one may want to subtract the density of “Balls” from “Called Strikes” to explore umpire influence:
Lastly, have fun and let me know what you think!
Carson,
I can’t wait to see this in action. Looks awesome! When I run this the menu on the left works but I get:
Error: could not find function “revalue”
Hi Jared,
Hmm. Haven’t seen that error before. Did the initial plot show up? Could you send me a list of the sequence of options you selected? It will help if I can reproduce your error.
-Carson
Many thanks, it showed up with the default options for me. I turned out that I just needed to update plyr to version 1.8. Thanks for doing this! I’d love to see something like this up on Fangraphs, btw.
Hi…I am trying to use this tool, but R complains when trying to install ‘Cairo’. I’m running on mac mountain lion with R 2.15.1. thanks for any help you can provide. I’m new to using R.
Hmm. I’m not sure why Cairo would fail to install. I would strongly recommend upgrading to R 3.0.0 and see if it still fails to install.
Note that Cairo is required to produce the animations. If you’re just looking for strike-zone density plots, you can use the web hosted option.
-Carson
[…] years ago (what? really?), I made this PITCHf/x visualization app. Although the app allows you upload a csv, it doesn't directly leverage the huge amount of […]
Carson,
I wanted to know if this tool was still available. The web hosted version appears to have been taken down. Since I’m not familiar with R I figured I would ask first before wading into the unknown.
Some of those links were old, but I’ve updated them now, thanks!