# 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
Curveball |
72.99 |
2205.29 |
46.90 |
-5.86 |
-3.36 |
BallCalled |
6.51 |
1.30 |
4.09 |
1.6 |
Changeup |
82.23 |
2003.63 |
200.45 |
8.85 |
25.44 |
FoulBallNotFieldable |
6.67 |
0.80 |
4.69 |
6.7 |
Changeup |
74.21 |
1524.96 |
233.34 |
14.53 |
12.70 |
StrikeCalled |
6.44 |
1.29 |
4.79 |
7.8 |
Changeup |
74.82 |
1597.80 |
228.13 |
12.32 |
12.83 |
FoulBallNotFieldable |
6.40 |
1.21 |
4.66 |
7.6 |
Changeup |
85.59 |
1949.14 |
208.13 |
9.22 |
18.63 |
FoulBallNotFieldable |
6.70 |
0.78 |
4.45 |
6.9 |
Changeup |
73.77 |
1321.85 |
242.91 |
13.65 |
8.87 |
BallCalled |
6.44 |
1.27 |
4.87 |
8.1 |
Changeup |
76.64 |
1624.52 |
254.64 |
17.44 |
6.48 |
InPlay |
6.44 |
1.33 |
4.60 |
8.5 |
Curveball |
74.28 |
2265.20 |
1.70 |
-0.30 |
-8.49 |
FoulBallNotFieldable |
6.47 |
1.12 |
4.19 |
0.1 |
Changeup |
73.61 |
1543.76 |
253.02 |
13.33 |
5.93 |
BallCalled |
6.45 |
1.29 |
4.37 |
8.4 |
Four-Seam |
85.24 |
2007.33 |
217.33 |
13.43 |
18.98 |
FoulBallNotFieldable |
6.57 |
0.76 |
4.60 |
7.2 |
Curveball |
73.17 |
2365.05 |
33.84 |
-6.75 |
-8.13 |
BallCalled |
6.55 |
1.00 |
4.18 |
1.1 |
Curveball |
73.21 |
2331.00 |
43.14 |
-4.95 |
-3.38 |
InPlay |
6.39 |
1.19 |
4.45 |
1.4 |
Changeup |
74.99 |
1484.70 |
237.48 |
13.77 |
10.74 |
StrikeCalled |
6.37 |
1.28 |
5.10 |
7.9 |
Changeup |
74.80 |
1496.29 |
233.06 |
14.67 |
12.88 |
StrikeCalled |
6.32 |
1.32 |
4.67 |
7.8 |
Curveball |
75.02 |
2335.44 |
31.41 |
-5.69 |
-7.49 |
FoulBallNotFieldable |
6.41 |
1.26 |
4.22 |
1.0 |
Changeup |
77.13 |
1654.79 |
245.01 |
14.92 |
8.58 |
FoulBallNotFieldable |
6.28 |
1.37 |
4.96 |
8.2 |
Four-Seam |
86.18 |
2037.15 |
205.16 |
9.80 |
22.30 |
InPlay |
6.61 |
0.80 |
4.54 |
6.8 |
Four-Seam |
85.02 |
1991.74 |
199.30 |
8.52 |
25.73 |
BallCalled |
6.50 |
0.77 |
4.72 |
6.6 |
Changeup |
73.88 |
1512.53 |
225.93 |
13.08 |
14.51 |
BallCalled |
6.49 |
1.09 |
4.30 |
7.5 |
Curveball |
75.30 |
2508.56 |
52.76 |
-8.97 |
-5.07 |
BallCalled |
6.45 |
1.02 |
4.41 |
1.8 |
Changeup |
84.68 |
1848.35 |
203.73 |
8.93 |
21.65 |
BallCalled |
6.57 |
0.72 |
4.58 |
6.8 |
Changeup |
85.25 |
1886.52 |
197.94 |
6.58 |
21.76 |
InPlay |
6.57 |
0.92 |
4.93 |
6.6 |
Changeup |
74.91 |
1517.70 |
229.41 |
14.24 |
14.04 |
BallCalled |
6.41 |
1.39 |
4.47 |
7.6 |
Changeup |
77.07 |
1628.88 |
251.08 |
17.17 |
7.50 |
StrikeCalled |
6.37 |
1.20 |
5.23 |
8.4 |
Changeup |
86.45 |
1921.38 |
216.20 |
10.89 |
16.14 |
FoulBallNotFieldable |
6.51 |
0.98 |
4.76 |
7.2 |
Changeup |
76.04 |
1536.58 |
248.94 |
17.45 |
8.36 |
StrikeCalled |
6.32 |
1.36 |
4.62 |
8.3 |
Curveball |
73.96 |
2310.49 |
39.45 |
-5.47 |
-4.96 |
BallCalled |
6.39 |
1.19 |
4.46 |
1.3 |
Changeup |
75.75 |
1545.23 |
247.98 |
17.06 |
8.58 |
BallCalled |
6.34 |
1.24 |
4.69 |
8.3 |
Curveball |
73.84 |
2208.84 |
32.58 |
-4.68 |
-5.67 |
StrikeCalled |
6.34 |
0.94 |
4.46 |
1.1 |
Curveball |
75.04 |
2388.84 |
42.09 |
-6.19 |
-5.20 |
StrikeSwinging |
6.41 |
1.01 |
4.40 |
1.4 |
Curveball |
74.18 |
2296.42 |
42.37 |
-5.42 |
-4.30 |
BallCalled |
6.42 |
0.85 |
4.60 |
1.4 |
Four-Seam |
85.49 |
2011.99 |
197.40 |
7.25 |
24.46 |
StrikeSwinging |
6.55 |
0.78 |
4.62 |
6.6 |
Changeup |
76.59 |
1712.16 |
243.46 |
18.71 |
11.07 |
StrikeSwinging |
6.29 |
1.36 |
4.64 |
8.1 |
Four-Seam |
87.00 |
1998.60 |
207.41 |
9.35 |
19.28 |
BallCalled |
6.53 |
0.66 |
4.78 |
6.9 |
Changeup |
75.21 |
1526.48 |
247.91 |
14.65 |
7.61 |
BallCalled |
6.33 |
1.28 |
5.02 |
8.3 |
Changeup |
76.35 |
1522.03 |
244.24 |
15.74 |
9.21 |
FoulBallNotFieldable |
6.34 |
1.23 |
4.87 |
8.1 |
Changeup |
77.49 |
1558.13 |
239.69 |
12.25 |
8.70 |
StrikeSwinging |
6.31 |
1.43 |
4.63 |
8.0 |
# 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: 37
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Matthew Martinez")
Summary Pitch Table for Matthew Martinez
Changeup |
59.46% |
22 |
7 |
15 |
31.82% |
68.18% |
77.61 |
1632.61 |
12.37 |
13.61 |
233.30 |
7.8 |
6.43 |
1.19 |
4.72 |
Curveball |
27.03% |
10 |
5 |
5 |
50.00% |
50.00% |
74.10 |
2321.51 |
-5.61 |
-5.43 |
36.62 |
1.2 |
6.43 |
1.09 |
4.35 |
Four-Seam |
13.51% |
5 |
2 |
3 |
40.00% |
60.00% |
85.79 |
2009.36 |
22.15 |
9.67 |
205.32 |
6.8 |
6.55 |
0.75 |
4.65 |
# Calculate maximum fastball velocity
max_fb_velocity <- detailed_pitch_table %>%
filter(AutoPitchType %in% c("Four-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: 87 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 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, 26)) + # 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")
)
