-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrike zone Depiction.Rmd
35 lines (25 loc) · 1.84 KB
/
Strike zone Depiction.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Show the difference between a Left Handed Hitter and Right Handed Hitter
install.packages("devtools")
install.packages("dplyr")
install.packages("ggplot2")
library(devtools)
library(ggplot2)
library(dplyr)
# Importing Data
devtools::install_github("Chrisboatto/Strike-Zone-difference/catcherframe/catcherframe.csv")
# Subset out all outputs of 0 in the calledstrike column. 1 = TRUE, 0 = FALSE
# If the output is 0 then the ball was not caught by the catcher for a strike therefore will not help in determining the strike zone
called_strike <- subset(catcherframe, calledstrike < 0)
# You can uses the ggplot function to create the strike zone for both left handed and right handed hitters.
# X and Y coordinates are the plate_x and plate_z columns but they're seperated by the batside of the hitter.
# You then can choose the density to which you would like to make apparent in the graph
# Through geom_rect() you can map out the strike zone to the proper size.
# Then through the facet_wrap() you can place both charts side by side to show the difference fairly easily.
ggplot(called_strike, aes(plate_x, plate_z, col= batside)) +
+ geom_density2d(aes_string(x="plate_x", y="plate_z"),
+ bins=100, size=1.4) +
+ geom_rect(mapping = aes(ymax = 3.6, ymin = 1.6,
+ xmax = -1.2, xmin = 1.2), alpha = 0, size=1.2,
+ colour = "black") +
+ facet_wrap(~batside)
# The above photo shows the difference between a right handed batters' strike zone and a left handed batters' strike zone. As you can see most strikes were called lower than higher and on the outside part of the plate for both batter sides. This shows that pitchers should attempt to throw more on the outside part of the plate to see better results and in turn batters should expect more pitches to be on the outside third of the plate.