# Filter the data for the pitcher Max Moss
Max_Moss_data <- data %>%
filter(Pitcher == "Moss, Max")
# Create a detailed table for each pitch
detailed_pitch_table <- Max_Moss_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
NA |
NA |
NA |
NA |
NA |
NA |
BallCalled |
NA |
NA |
NA |
NA |
Changeup |
86.07 |
1848.34 |
237.30 |
15.45 |
11.24 |
BallCalled |
4.58 |
3.39 |
5.50 |
7.9 |
Changeup |
86.67 |
1929.33 |
250.03 |
18.95 |
8.24 |
FoulBallNotFieldable |
4.91 |
2.46 |
5.60 |
8.3 |
Changeup |
77.96 |
1669.31 |
256.18 |
12.07 |
4.33 |
FoulBallNotFieldable |
4.56 |
2.69 |
5.85 |
8.5 |
Changeup |
78.22 |
1788.91 |
251.46 |
15.93 |
6.79 |
FoulBallNotFieldable |
4.57 |
2.49 |
5.90 |
8.4 |
Sinker |
87.71 |
1970.82 |
237.70 |
15.99 |
11.34 |
BallCalled |
4.67 |
2.57 |
5.65 |
7.9 |
Changeup |
88.08 |
1852.64 |
228.17 |
13.12 |
12.94 |
FoulBallNotFieldable |
4.74 |
2.37 |
5.71 |
7.6 |
Changeup |
78.04 |
1961.59 |
269.59 |
19.50 |
1.69 |
BallCalled |
4.42 |
2.52 |
5.87 |
9.0 |
Changeup |
86.99 |
2001.29 |
241.59 |
20.92 |
12.58 |
StrikeCalled |
4.62 |
2.42 |
5.83 |
8.1 |
Changeup |
78.05 |
1999.45 |
272.60 |
18.90 |
0.58 |
BallCalled |
4.47 |
2.42 |
5.96 |
9.1 |
Changeup |
86.56 |
1915.07 |
243.24 |
18.39 |
10.41 |
FoulBallNotFieldable |
4.52 |
2.59 |
5.80 |
8.1 |
Curveball |
75.88 |
2215.75 |
73.50 |
-10.22 |
-1.47 |
BallCalled |
4.52 |
2.62 |
5.36 |
2.5 |
Changeup |
86.80 |
1853.72 |
239.84 |
15.01 |
10.00 |
StrikeSwinging |
4.64 |
2.52 |
5.68 |
8.0 |
Changeup |
85.20 |
1839.18 |
233.06 |
14.98 |
12.76 |
BallCalled |
4.85 |
2.26 |
5.72 |
7.8 |
Changeup |
86.43 |
1913.00 |
242.63 |
18.60 |
11.10 |
InPlay |
4.78 |
2.09 |
5.55 |
8.1 |
# 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: 15
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Max Moss")
Summary Pitch Table for Max Moss
Changeup |
80.00% |
12 |
4 |
8 |
33.33% |
66.67% |
83.76 |
1880.99 |
8.55 |
16.82 |
247.14 |
8.2 |
4.64 |
2.52 |
5.75 |
Curveball |
6.67% |
1 |
1 |
0 |
100.00% |
0.00% |
75.88 |
2215.75 |
-1.47 |
-10.22 |
73.50 |
2.5 |
4.52 |
2.62 |
5.36 |
Sinker |
6.67% |
1 |
1 |
0 |
100.00% |
0.00% |
87.71 |
1970.82 |
11.34 |
15.99 |
237.70 |
7.9 |
4.67 |
2.57 |
5.65 |
NA |
6.67% |
1 |
1 |
0 |
100.00% |
0.00% |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
NaN |
# 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.71 mph
# Prepare data for plotting pitch locations
pitch_location_data <- Max_Moss_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)) +
scale_y_continuous(limits = c(-25, 25)) +
labs(title = "Pitch Movement for Max Moss",
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")
)
