# Filter the data for the pitcher Matthew Martinez
Brian_Foley_data <- data %>%
filter(Pitcher == "Martinez, Matthew")
# 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 Matthew Martinez")
Detailed Pitch Table for Matthew Martinez
Changeup |
73.15 |
1768.65 |
219.43 |
16.25 |
21.73 |
BallCalled |
6.23 |
1.16 |
4.65 |
7.3 |
Curveball |
73.80 |
2287.02 |
70.51 |
-6.99 |
-0.80 |
StrikeCalled |
6.24 |
1.23 |
4.70 |
2.4 |
Four-Seam |
84.48 |
2029.41 |
205.60 |
11.38 |
25.18 |
BallCalled |
6.37 |
0.56 |
5.21 |
6.9 |
Changeup |
74.46 |
1782.36 |
239.61 |
20.14 |
13.72 |
StrikeSwinging |
6.07 |
1.23 |
5.17 |
8.0 |
Changeup |
75.22 |
1627.06 |
235.53 |
17.80 |
14.04 |
StrikeSwinging |
5.97 |
1.33 |
5.08 |
7.9 |
Changeup |
74.40 |
1718.21 |
233.44 |
18.27 |
15.38 |
StrikeCalled |
6.02 |
1.32 |
4.91 |
7.8 |
Curveball |
73.86 |
2242.19 |
13.93 |
-2.80 |
-9.53 |
StrikeSwinging |
6.17 |
1.32 |
4.83 |
0.5 |
Changeup |
74.83 |
1783.75 |
253.27 |
22.38 |
8.56 |
InPlay |
5.99 |
1.50 |
4.85 |
8.4 |
Changeup |
73.31 |
1769.55 |
236.60 |
17.26 |
13.26 |
StrikeCalled |
6.08 |
1.25 |
4.82 |
7.9 |
Curveball |
74.05 |
2288.72 |
54.57 |
-3.73 |
-0.80 |
StrikeCalled |
6.20 |
1.17 |
4.73 |
1.8 |
Changeup |
75.95 |
1821.30 |
243.56 |
19.42 |
11.51 |
StrikeSwinging |
5.92 |
1.29 |
4.94 |
8.1 |
Changeup |
85.14 |
1820.18 |
213.06 |
13.60 |
22.37 |
BallCalled |
6.19 |
0.76 |
5.38 |
7.1 |
Changeup |
74.40 |
1578.91 |
255.94 |
19.90 |
6.94 |
StrikeSwinging |
5.99 |
1.27 |
4.98 |
8.5 |
Changeup |
77.82 |
1718.10 |
220.25 |
13.76 |
17.99 |
BallCalled |
5.94 |
1.21 |
5.21 |
7.3 |
Curveball |
74.57 |
2363.03 |
53.72 |
-8.51 |
-4.41 |
InPlay |
6.17 |
1.08 |
4.76 |
1.8 |
Curveball |
73.54 |
2287.91 |
47.70 |
-6.55 |
-4.28 |
StrikeCalled |
6.07 |
1.00 |
4.67 |
1.6 |
Changeup |
77.23 |
1785.40 |
251.19 |
21.46 |
8.93 |
FoulBallNotFieldable |
5.93 |
1.21 |
5.28 |
8.4 |
Four-Seam |
86.25 |
1878.18 |
198.93 |
7.30 |
22.67 |
BallCalled |
6.24 |
0.50 |
5.13 |
6.6 |
Curveball |
75.78 |
2346.41 |
33.50 |
-3.72 |
-3.81 |
FoulBallNotFieldable |
6.05 |
1.22 |
4.85 |
1.1 |
Four-Seam |
86.60 |
1987.33 |
213.05 |
11.96 |
19.79 |
FoulBallNotFieldable |
6.14 |
0.48 |
5.24 |
7.1 |
Changeup |
76.42 |
1673.85 |
234.53 |
14.14 |
12.03 |
FoulBallNotFieldable |
5.93 |
1.15 |
5.22 |
7.8 |
Changeup |
77.78 |
1722.65 |
248.74 |
19.65 |
9.33 |
InPlay |
5.93 |
1.30 |
5.18 |
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: 22
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Matthew Martinez")
Summary Pitch Table for Matthew Martinez
Changeup |
59.09% |
13 |
3 |
10 |
23.08% |
76.92% |
76.16 |
1736.15 |
13.52 |
18.00 |
237.32 |
7.9 |
6.01 |
1.23 |
5.05 |
Curveball |
27.27% |
6 |
0 |
6 |
0.00% |
100.00% |
74.27 |
2302.55 |
-3.94 |
-5.38 |
45.66 |
1.5 |
6.15 |
1.17 |
4.76 |
Four-Seam |
13.64% |
3 |
2 |
1 |
66.67% |
33.33% |
85.78 |
1964.97 |
22.55 |
10.21 |
205.86 |
6.9 |
6.25 |
0.51 |
5.19 |
# 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("Matthew Martinez maximum FB velocity: ", max_fb_velocity, "mph\n")
## Matthew Martinez maximum FB velocity: 86.6 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.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 Matthew Martinez",
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")
)
