Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
images
README.md
pitchviz.R

README.md

MLB pitch visualization

An R script that, when given a year, team and pitcher, produces visualizations of every pitch thrown by that pitcher in that year for several different pitch outcomes.

It will produce 18 different PNG graphs, three for each of six differnet pitch outcomes: called ball, foul, hit, batted out, swinging strike, called strike. For each outcome, it will produce one graph of all pitches, and then one graph each for just matchups vs. left-handed batters and right-handed batters.

The function takes three parameters, all expressed inside quotation marks:

  • "pitchyear", a four-digit year. PitchFX debuted in 2007 and gradually expanded; the further back in time, the greater the chance of errors or missing data.
  • "team", a three-character string reflecting the team's city: "bos", "sea", etc. For two-team cities, the third digit reflects the league: for example, "chn" instead of "chc"; "lan" instead of "lad".
  • "pitchername", the generally recognized first and last name of a pitcher. For example, "Jake Arrieta" instead of "Jacob Arrieta."

The script will take a few minutes to run, due to the large amount of data it needs to download.

Based on a tutorial by Bill Petti at The Hardball Times.

Examples of the outputs:

> pitchviz("2015","chn","Jake Arrieta")

Jake Arrieta swinging strikes

> pitchviz("2015","lan","Clayton Kershaw")

Kershaw swinging strikes

> pitchviz("2015","chn","Jon Lester")

Lester LHB balls Lester RHB balls