# Filter the data for the pitcher Brian Foley
Brian_Foley_data <- data %>%
filter(Pitcher == "Foley, Brian")
# 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 Brian Foley")
Detailed Pitch Table for Brian Foley
Four-Seam |
94.44 |
2372.94 |
170.30 |
-1.92 |
12.28 |
BallCalled |
6.07 |
1.51 |
6.38 |
5.7 |
Four-Seam |
94.26 |
2399.12 |
175.55 |
-1.07 |
14.77 |
FoulBallNotFieldable |
6.14 |
1.33 |
6.44 |
5.9 |
Four-Seam |
92.69 |
2482.74 |
196.59 |
3.22 |
11.90 |
InPlay |
6.03 |
1.63 |
6.31 |
6.6 |
Four-Seam |
94.05 |
2376.67 |
189.69 |
2.80 |
17.46 |
StrikeSwinging |
6.07 |
1.66 |
6.14 |
6.3 |
Four-Seam |
94.28 |
2307.49 |
203.16 |
4.81 |
12.19 |
InPlay |
6.10 |
1.72 |
6.21 |
6.8 |
Sinker |
94.96 |
2331.47 |
245.32 |
15.44 |
8.20 |
StrikeCalled |
5.80 |
1.78 |
6.11 |
8.2 |
Four-Seam |
94.70 |
2452.33 |
193.82 |
4.02 |
17.31 |
FoulBallNotFieldable |
6.06 |
1.47 |
6.25 |
6.5 |
Slider |
81.58 |
2922.30 |
119.23 |
-12.96 |
8.60 |
BallCalled |
5.48 |
2.13 |
5.81 |
4.0 |
Slider |
82.41 |
1398.60 |
117.39 |
-12.11 |
7.53 |
BallCalled |
5.46 |
2.13 |
5.77 |
3.9 |
Four-Seam |
94.40 |
2602.68 |
188.03 |
1.35 |
10.47 |
FoulBallNotFieldable |
6.09 |
1.38 |
6.21 |
6.3 |
Four-Seam |
94.14 |
2533.52 |
202.16 |
3.82 |
10.28 |
BallCalled |
6.07 |
1.55 |
6.47 |
6.7 |
Four-Seam |
93.18 |
2514.48 |
182.78 |
0.48 |
10.73 |
BallCalled |
6.07 |
1.50 |
6.41 |
6.1 |
Sinker |
94.79 |
2335.40 |
256.44 |
18.53 |
5.51 |
BallCalled |
5.81 |
1.66 |
5.93 |
8.5 |
Sinker |
94.04 |
2324.94 |
247.29 |
16.28 |
7.79 |
BallCalled |
5.64 |
1.78 |
6.23 |
8.2 |
# 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: 14
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Brian Foley")
Summary Pitch Table for Brian Foley
Four-Seam |
64.29% |
9 |
3 |
6 |
33.33% |
66.67% |
94.02 |
2449.11 |
13.04 |
1.95 |
189.12 |
6.3 |
6.08 |
1.53 |
6.31 |
Sinker |
21.43% |
3 |
2 |
1 |
66.67% |
33.33% |
94.60 |
2330.60 |
7.17 |
16.75 |
249.68 |
8.3 |
5.75 |
1.74 |
6.09 |
Slider |
14.29% |
2 |
2 |
0 |
100.00% |
0.00% |
82.00 |
2160.45 |
8.06 |
-12.54 |
118.31 |
4.0 |
5.47 |
2.13 |
5.79 |
# 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("Brian Foley maximum FB velocity: ", max_fb_velocity, "mph\n")
## Brian Foley maximum FB velocity: 94.96 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 Brian Foley",
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 for", unique(detailed_pitch_table$AutoPitchType)),
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")
)
