# 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
Curveball |
77.21 |
2118.06 |
61.53 |
-10.32 |
-3.84 |
InPlay |
4.77 |
3.41 |
5.06 |
2.1 |
Changeup |
77.35 |
1860.36 |
268.37 |
19.22 |
2.21 |
BallCalled |
4.62 |
3.38 |
5.47 |
8.9 |
Changeup |
86.35 |
1912.46 |
240.76 |
15.70 |
10.14 |
BallCalled |
4.75 |
3.34 |
5.22 |
8.0 |
Changeup |
78.48 |
1949.12 |
248.04 |
19.10 |
9.30 |
BallCalled |
4.59 |
3.34 |
5.44 |
8.3 |
Changeup |
85.51 |
1925.46 |
233.72 |
15.37 |
12.63 |
StrikeCalled |
4.81 |
3.37 |
5.22 |
7.8 |
Changeup |
84.92 |
1906.20 |
224.87 |
13.05 |
14.48 |
FoulBallNotFieldable |
4.75 |
3.33 |
5.17 |
7.5 |
Curveball |
77.78 |
2139.49 |
50.22 |
-7.88 |
-4.95 |
FoulBallNotFieldable |
4.68 |
3.36 |
4.97 |
1.7 |
Sinker |
88.64 |
1955.68 |
239.50 |
15.20 |
10.25 |
BallCalled |
4.92 |
3.26 |
5.36 |
8.0 |
Changeup |
85.50 |
1872.44 |
235.57 |
14.86 |
11.52 |
FoulBallNotFieldable |
4.83 |
3.45 |
5.34 |
7.9 |
Changeup |
78.28 |
1766.10 |
260.37 |
17.77 |
4.65 |
StrikeCalled |
4.49 |
3.56 |
5.46 |
8.7 |
Sinker |
87.83 |
1904.46 |
225.75 |
15.47 |
16.41 |
StrikeSwinging |
4.78 |
3.47 |
5.19 |
7.5 |
Changeup |
86.98 |
1895.24 |
228.25 |
14.47 |
14.26 |
StrikeCalled |
4.68 |
3.24 |
5.22 |
7.6 |
Changeup |
78.50 |
1781.16 |
266.20 |
18.62 |
2.77 |
BallCalled |
4.53 |
3.36 |
5.54 |
8.9 |
Curveball |
78.32 |
2210.81 |
65.66 |
-8.16 |
-2.11 |
BallCalled |
4.55 |
3.46 |
4.93 |
2.2 |
Changeup |
86.43 |
1939.23 |
229.30 |
13.65 |
13.13 |
InPlay |
4.65 |
3.42 |
5.15 |
7.6 |
Changeup |
82.90 |
1793.12 |
240.78 |
17.48 |
11.20 |
InPlay |
4.85 |
3.51 |
5.09 |
8.0 |
Changeup |
84.67 |
1936.54 |
239.08 |
20.18 |
13.49 |
InPlay |
4.78 |
3.39 |
5.26 |
8.0 |
Slider |
75.87 |
2162.93 |
117.87 |
-3.89 |
3.53 |
BallCalled |
4.72 |
3.44 |
5.04 |
3.9 |
Changeup |
85.39 |
1964.77 |
240.79 |
18.88 |
11.96 |
BallCalled |
4.77 |
3.37 |
5.29 |
8.0 |
Changeup |
85.38 |
1884.97 |
246.60 |
22.51 |
11.18 |
InPlay |
4.83 |
3.29 |
5.16 |
8.2 |
Curveball |
75.32 |
2168.87 |
70.51 |
-8.68 |
-1.48 |
BallCalled |
4.65 |
3.39 |
5.28 |
2.4 |
Changeup |
85.98 |
2020.89 |
244.69 |
19.24 |
10.43 |
BallCalled |
4.76 |
3.25 |
5.23 |
8.2 |
Changeup |
86.61 |
1996.58 |
251.38 |
22.35 |
8.89 |
InPlay |
4.82 |
3.29 |
5.26 |
8.4 |
# 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 %in% c("BallCalled", "BallinDirt")),
Strikes = sum(!PitchCall %in% c("BallCalled", "BallinDirt")), # 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: 23
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Max Moss")
Summary Pitch Table for Max Moss
Changeup |
69.57% |
16 |
6 |
10 |
37.50% |
62.50% |
83.70 |
1900.29 |
10.14 |
17.65 |
243.67 |
8.1 |
4.72 |
3.37 |
5.28 |
Curveball |
17.39% |
4 |
2 |
2 |
50.00% |
50.00% |
77.16 |
2159.31 |
-3.09 |
-8.76 |
61.98 |
2.1 |
4.66 |
3.41 |
5.06 |
Sinker |
8.70% |
2 |
1 |
1 |
50.00% |
50.00% |
88.24 |
1930.07 |
13.33 |
15.34 |
232.62 |
7.8 |
4.85 |
3.37 |
5.28 |
Slider |
4.35% |
1 |
1 |
0 |
100.00% |
0.00% |
75.87 |
2162.93 |
3.53 |
-3.89 |
117.87 |
3.9 |
4.72 |
3.44 |
5.04 |
# 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: 88.64 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", "FoulBall", "FoulBallFieldable", "FoulBallNotFieldable", "InPlay"), "Swing", "Take"),
Chase = ifelse(SwingTake == "Swing" & (PitchSide < -0.85 | PitchSide > 0.85 | 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.85, xmax = 0.85, 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")
)
