knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(CalledStrike) library(dplyr)
There are three functions for visualizing pitch locations.
The function location_compare()
will graph the pitch location for a data frame or list of data frames.
The function location_count()
will show the locations of pitches for a specific pitcher on a particular count.
The function location_count_compare()
will graph the pitch locations for a specific pitcher for several values of the count.
The package includes the dataset sc_pitchers_2019 that contains Statcast data for 20 pitchers for the 2019 season.
Suppose we want to compare the locations of the fastballs thrown by Aaron Nola and Trevor Bauer.
I find the subset of data I need and then create a list dividing the data by pitcher.
d <- filter(sc_pitchers_2019, pitcher %in% c(605400, 545333), pitch_type == "FF") ds <- split(d, d$pitcher) names(ds) <- c("Bauer", "Nola")
Now we can construct the graph.
location_compare(ds)
Suppose we want to look at the locations of Aaron Nola’s pitches on a 0-0 count. I can find Nola’s MLBAM id number by use of the chadwick dataset (also included in the package) that contains the id numbers for all players.
chadwick %>% filter(name_last == "Nola", name_first == "Aaron")
To produce the graph, type
location_count(sc_pitchers_2019, 605400, "Aaron Nola", "0-0")
Suppose we want to compare Nola's pitch locations across the counts "0-0", "1-0", "0-1", "0-2"
location_count_compare(sc_pitchers_2019, 605400, "Aaron Nola", "R", "Offspeed", c("0-0", "1-0", "0-1", "0-2"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.