The package is primarily a data package, and has no native plotting tools. However, there are several plotting options available by leveraging one of the R language's excellent plotting libraries.
For all of the following examples, we will use The pitch data for Jake Arrieta's no-hitter, which occurred on April 21, 2016.
library(mlbgameday) library(dplyr) # Grap some Gameday data. We're specifically looking for Jake Arrieta's no-hitter. gamedat <- get_payload(start = "2016-04-21", end = "2016-04-21") # Subset that atbat table to only Arrieta's pitches and join it with the pitch table. pitches <- inner_join(gamedat$pitch, gamedat$atbat, by = c("num", "url")) %>% subset(pitcher_name == "Jake Arrieta")
The ggplot2 package can be used stand-alone, or in conjunction with Carson Silvert's pitchRx package, which has additional visualization offerings that are based on ggplot2.
library(ggplot2) # basic example ggplot() + geom_point(data=pitches, aes(x=px, y=pz, shape=type, col=pitch_type)) + coord_equal() + geom_path(aes(x, y), data = mlbgameday::kzone)
Using the same simple ggplot example, we can use facet_grid(. ~ stand)
to segment the pitches thrown to right-handers from those thrown to left-handers.
# basic example with stand. ggplot() + geom_point(data=pitches, aes(x=px, y=pz, shape=type, col=pitch_type)) + facet_grid(. ~ stand) + coord_equal() + geom_path(aes(x, y), data = mlbgameday::kzone)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.