# Filter the data for the pitcher Foley
Foley_data <- Sanford64 %>%
filter(Pitcher == "Foley, Brian")
# Create a detailed table for each pitch
detailed_pitch_table <- Foley_data %>%
select(AutoPitchType, RelSpeed, SpinRate, SpinAxis, HorzBreak, InducedVertBreak, PitchCall) %>%
rename(
ReleaseSpeed = RelSpeed,
Tilt = SpinAxis,
HorizontalBreak = HorzBreak,
InducedVerticalBreak = InducedVertBreak
) %>%
mutate(
ReleaseSpeed = round(ReleaseSpeed, 2),
SpinRate = round(SpinRate, 2),
Tilt = round(Tilt, 2),
HorizontalBreak = round(HorizontalBreak, 2),
InducedVerticalBreak = round(InducedVerticalBreak, 2),
ClockTilt = round((Tilt / 30) %% 12, 1) # Interpret Tilt as clock face
)
# Display the detailed table
knitr::kable(detailed_pitch_table, caption = "Detailed Pitch Table for Foley")
Detailed Pitch Table for Foley
Sinker |
92.83 |
2477.77 |
239.37 |
15.52 |
10.22 |
StrikeCalled |
8.0 |
Sinker |
93.85 |
2514.47 |
242.97 |
17.05 |
9.70 |
InPlay |
8.1 |
Four-Seam |
95.00 |
2610.99 |
196.56 |
6.02 |
21.24 |
BallCalled |
6.6 |
Sinker |
94.15 |
2417.68 |
233.31 |
14.89 |
12.08 |
InPlay |
7.8 |
Slider |
79.53 |
2724.88 |
101.91 |
-15.65 |
4.62 |
BallCalled |
3.4 |
Sinker |
94.82 |
2539.59 |
237.76 |
18.07 |
12.47 |
StrikeSwinging |
7.9 |
Sinker |
91.49 |
2523.25 |
232.70 |
11.88 |
10.09 |
BallCalled |
7.8 |
Sinker |
93.61 |
2515.58 |
239.80 |
12.92 |
8.50 |
StrikeCalled |
8.0 |
Slider |
80.69 |
2927.52 |
77.10 |
-18.40 |
-2.80 |
InPlay |
2.6 |
# Create a summary table
pitch_summary <- detailed_pitch_table %>%
group_by(AutoPitchType) %>%
summarise(
TotalPitches = n(),
Balls = sum(PitchCall == "BallCalled"),
Strikes = sum(PitchCall != "BallCalled"), # Count everything not a ball as a strike
BallPercentage = sprintf("%.2f%%", Balls / TotalPitches * 100),
StrikePercentage = sprintf("%.2f%%", Strikes / TotalPitches * 100),
AvgVelocity = round(mean(ReleaseSpeed, na.rm = TRUE), 2),
AvgSpinRate = round(mean(SpinRate, na.rm = TRUE), 2),
AvgInducedVertBreak = round(mean(InducedVerticalBreak, na.rm = TRUE), 2),
AvgHorzBreak = round(mean(HorizontalBreak, na.rm = TRUE), 2),
AvgTilt = round(mean(Tilt, na.rm = TRUE), 2),
AvgClockTilt = round(mean(ClockTilt, na.rm = TRUE), 1) # Clock face interpretation
)
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Foley")
Summary Pitch Table for Foley
Four-Seam |
1 |
1 |
0 |
100.00% |
0.00% |
95.00 |
2610.99 |
21.24 |
6.02 |
196.56 |
6.6 |
Sinker |
6 |
1 |
5 |
16.67% |
83.33% |
93.46 |
2498.06 |
10.51 |
15.05 |
237.65 |
7.9 |
Slider |
2 |
1 |
1 |
50.00% |
50.00% |
80.11 |
2826.20 |
0.91 |
-17.02 |
89.50 |
3.0 |
# Prepare data for plotting pitch locations
pitch_location_data <- Foley_data %>%
select(AutoPitchType, PlateLocHeight, PlateLocSide, PitchCall) %>%
rename(
PitchHeight = PlateLocHeight,
PitchSide = PlateLocSide
) %>%
mutate(
SwingTake = ifelse(PitchCall %in% c("StrikeSwinging", "FoulBallNonSwinging", "FoulBallFieldable", "FoulBallNotFieldable", "InPlay"), "Swing", "Take"),
Chase = ifelse(SwingTake == "Swing" & (PitchSide < -0.75 | PitchSide > 0.75 | PitchHeight < 1.5 | PitchHeight > 3.5), "Chase", "Non-Chase")
)
# Create the scatter plot with specified strike zone boxes
ggplot(pitch_location_data, aes(x = PitchSide, y = PitchHeight, color = SwingTake, shape = Chase)) +
geom_point(size = 3) + # Increase point size
geom_rect(aes(xmin = -0.5, xmax = 0.5, ymin = 1.75, ymax = 3.25), fill = NA, color = "red", linetype = "solid", size = 1) + # Red box
geom_rect(aes(xmin = -0.75, xmax = 0.75, ymin = 1.5, ymax = 3.5), fill = NA, color = "black", linetype = "solid", size = 1) + # Black box
geom_rect(aes(xmin = -1.25, xmax = 1.25, ymin = 1.25, ymax = 3.75), fill = NA, color = "gray", linetype = "solid", size = 1) + # Gray box
scale_x_continuous(limits = c(-2, 2)) +
scale_y_continuous(limits = c(0, 5)) +
coord_fixed(ratio = 1) + # Adjust ratio to shrink vertical distance
labs(title = "Pitch Locations for Foley",
x = "Horizontal Location (feet)",
y = "Vertical Location (feet)",
color = "Swing/Take",
shape = "Chase") +
facet_wrap(~ AutoPitchType) + # Create individual graphs for each pitch type
geom_text(aes(x = -1.75, y = 5, label = "RHH"), color = "black", size = 3, hjust = 0) + # Label for RHH
geom_text(aes(x = 1.75, y = 5, label = "LHH"), color = "black", size = 3, hjust = 1) + # Label for LHH
theme_minimal() +
theme(
legend.position = "right",
panel.grid.major = element_line(color = "grey80"),
panel.grid.minor = element_line(color = "grey90"),
axis.text = element_text(color = "black"),
axis.title = element_text(color = "black"),
plot.title = element_text(color = "black"),
legend.background = element_rect(fill = "white", color = NA),
legend.key = element_rect(fill = "white", color = NA),
legend.text = element_text(color = "black"),
legend.title = element_text(color = "black")
)

# Create the scatter plot for horizontal and vertical breaks
ggplot(detailed_pitch_table, aes(x = HorizontalBreak, y = InducedVerticalBreak, color = AutoPitchType)) +
geom_point(size = 3) + # Increase point size
labs(title = "Pitch Movement for Foley",
x = "Horizontal Break (inches)",
y = "Induced Vertical Break (inches)",
color = "Pitch Type") +
theme_minimal() +
theme(
legend.position = "right",
panel.grid.major = element_line(color = "grey80"),
panel.grid.minor = element_line(color = "grey90"),
axis.text = element_text(color = "black"),
axis.title = element_text(color = "black"),
plot.title = element_text(color = "black"),
legend.background = element_rect(fill = "white", color = NA),
legend.key = element_rect(fill = "white", color = NA),
legend.text = element_text(color = "black"),
legend.title = element_text(color = "black")
)
