# Filter the data for the pitcher Max Moss
Brian_Foley_data <- data %>%
filter(Pitcher == "Moss, Max")
# Create a detailed table for each pitch
detailed_pitch_table <- Brian_Foley_data %>%
select(AutoPitchType, RelSpeed, SpinRate, SpinAxis, HorzBreak, InducedVertBreak, PitchCall, RelHeight, RelSide, Extension) %>%
rename(
ReleaseSpeed = RelSpeed,
Tilt = SpinAxis,
HorizontalBreak = HorzBreak,
InducedVerticalBreak = InducedVertBreak,
ReleaseHeight = RelHeight,
ReleaseSide = RelSide
) %>%
mutate(
ReleaseSpeed = round(ReleaseSpeed, 2),
SpinRate = round(SpinRate, 2),
Tilt = round(Tilt, 2),
HorizontalBreak = round(HorizontalBreak, 2),
InducedVerticalBreak = round(InducedVerticalBreak, 2),
ReleaseHeight = round(ReleaseHeight, 2),
ReleaseSide = round(ReleaseSide, 2),
Extension = round(Extension, 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 Max Moss")
Detailed Pitch Table for Max Moss
Changeup |
77.83 |
2028.59 |
260.01 |
18.55 |
4.91 |
BallinDirt |
4.32 |
3.37 |
6.27 |
8.7 |
Changeup |
87.00 |
1957.87 |
245.06 |
16.01 |
8.72 |
StrikeCalled |
4.59 |
3.27 |
5.87 |
8.2 |
Changeup |
78.84 |
2013.27 |
258.68 |
17.33 |
4.96 |
BallCalled |
4.38 |
3.44 |
6.35 |
8.6 |
Changeup |
86.08 |
1923.47 |
243.04 |
18.41 |
10.69 |
BallCalled |
4.58 |
3.31 |
5.89 |
8.1 |
Sinker |
87.21 |
2044.74 |
244.56 |
17.75 |
9.66 |
BallCalled |
4.65 |
3.11 |
6.00 |
8.2 |
Sinker |
86.69 |
2054.61 |
235.68 |
16.04 |
12.26 |
StrikeCalled |
4.58 |
3.25 |
5.83 |
7.9 |
Changeup |
86.72 |
1932.97 |
244.00 |
18.55 |
10.27 |
BallCalled |
4.49 |
3.12 |
6.00 |
8.1 |
Sinker |
87.47 |
2029.01 |
238.25 |
16.66 |
11.65 |
FoulBallNotFieldable |
4.58 |
3.20 |
5.96 |
7.9 |
Curveball |
77.85 |
2163.37 |
64.84 |
-8.66 |
-2.54 |
FoulBallNotFieldable |
4.44 |
3.41 |
5.72 |
2.2 |
Sinker |
87.67 |
1977.50 |
234.60 |
14.24 |
11.52 |
InPlay |
4.55 |
3.31 |
5.79 |
7.8 |
Changeup |
87.39 |
1946.08 |
245.77 |
18.81 |
9.82 |
StrikeSwinging |
4.53 |
3.41 |
5.91 |
8.2 |
Changeup |
78.78 |
1919.91 |
251.69 |
18.42 |
7.70 |
StrikeCalled |
4.34 |
3.35 |
6.19 |
8.4 |
Changeup |
87.85 |
1926.03 |
247.80 |
19.01 |
9.07 |
StrikeCalled |
4.49 |
3.44 |
5.78 |
8.3 |
# Calculate the total number of pitches
total_pitches <- nrow(detailed_pitch_table)
# Create a summary table
pitch_summary <- detailed_pitch_table %>%
group_by(AutoPitchType) %>%
summarise(
TotalPitches = n(),
Usage = sprintf("%.2f%%", n() / total_pitches * 100),
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
AvgReleaseHeight = round(mean(ReleaseHeight, na.rm = TRUE), 2),
AvgReleaseSide = round(mean(ReleaseSide, na.rm = TRUE), 2),
AvgExtension = round(mean(Extension, na.rm = TRUE), 2)
) %>%
select(AutoPitchType, Usage, everything())
# Display the total number of pitches
cat("Total number of pitches thrown: ", total_pitches, "\n")
## Total number of pitches thrown: 13
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Max Moss")
Summary Pitch Table for Max Moss
Changeup |
61.54% |
8 |
3 |
5 |
37.50% |
62.50% |
83.81 |
1956.02 |
8.27 |
18.14 |
249.51 |
8.3 |
4.46 |
3.34 |
6.03 |
Curveball |
7.69% |
1 |
0 |
1 |
0.00% |
100.00% |
77.85 |
2163.37 |
-2.54 |
-8.66 |
64.84 |
2.2 |
4.44 |
3.41 |
5.72 |
Sinker |
30.77% |
4 |
1 |
3 |
25.00% |
75.00% |
87.26 |
2026.47 |
11.27 |
16.17 |
238.27 |
8.0 |
4.59 |
3.22 |
5.89 |
# Calculate maximum fastball velocity
max_fb_velocity <- detailed_pitch_table %>%
filter(AutoPitchType %in% c("Four-Seam", "Two-Seam", "Sinker", "Cutter")) %>%
summarise(MaxFBVelocity = max(ReleaseSpeed, na.rm = TRUE)) %>%
pull(MaxFBVelocity)
# Display the maximum fastball velocity
cat("Max Moss maximum FB velocity: ", max_fb_velocity, "mph\n")
## Max Moss maximum FB velocity: 87.67 mph
# Prepare data for plotting pitch locations
pitch_location_data <- Brian_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) +
geom_rect(aes(xmin = -0.5, xmax = 0.5, ymin = 1.75, ymax = 3.25), fill = NA, color = "red", linetype = "solid", size = 1) +
geom_rect(aes(xmin = -0.75, xmax = 0.75, ymin = 1.5, ymax = 3.5), fill = NA, color = "black", linetype = "solid", size = 1) +
geom_rect(aes(xmin = -1.25, xmax = 1.25, ymin = 1.25, ymax = 3.75), fill = NA, color = "gray", linetype = "solid", size = 1) +
scale_x_continuous(limits = c(-2, 2)) +
scale_y_continuous(limits = c(0, 5)) +
coord_fixed(ratio = 1) +
labs(title = "Pitch Locations for Max Moss",
x = "Horizontal Location (feet)",
y = "Vertical Location (feet)",
color = "Swing/Take",
shape = "Chase") +
facet_wrap(~ AutoPitchType) +
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
scale_x_continuous(limits = c(-25, 25)) + # Set horizontal limits to +/- 25 inches
scale_y_continuous(limits = c(-25, 25)) + # Set vertical limits to +/- 25 inches
labs(title = paste("Pitch Movement"),
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")
)
