# Filter the data for the pitcher Tommy Flaherty
Brian_Foley_data <- data %>%
filter(Pitcher == "Flaherty, Tommy")
# 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 Tommy Flaherty")
Detailed Pitch Table for Tommy Flaherty
Four-Seam |
87.11 |
2279.83 |
205.71 |
6.49 |
14.61 |
FoulBallNotFieldable |
5.77 |
2.34 |
6.04 |
6.9 |
Four-Seam |
87.90 |
2308.24 |
188.44 |
2.48 |
17.79 |
BallCalled |
5.81 |
2.37 |
6.14 |
6.3 |
Slider |
79.01 |
2456.10 |
106.46 |
-13.49 |
5.37 |
FoulBallNotFieldable |
5.79 |
2.76 |
5.30 |
3.5 |
Slider |
79.86 |
2452.37 |
83.18 |
-7.17 |
0.57 |
InPlay |
5.67 |
2.49 |
5.50 |
2.8 |
Four-Seam |
86.30 |
2286.63 |
191.38 |
3.24 |
17.32 |
BallCalled |
5.86 |
2.35 |
6.19 |
6.4 |
Four-Seam |
86.51 |
2237.28 |
194.24 |
3.93 |
16.72 |
StrikeCalled |
5.74 |
2.34 |
6.12 |
6.5 |
Slider |
79.38 |
2416.72 |
91.29 |
-8.81 |
1.71 |
FoulBallNotFieldable |
5.75 |
2.56 |
5.56 |
3.0 |
Four-Seam |
87.60 |
2331.34 |
199.32 |
5.14 |
15.66 |
BallCalled |
5.84 |
2.41 |
6.09 |
6.6 |
Four-Seam |
87.22 |
2321.84 |
184.24 |
1.31 |
18.78 |
StrikeSwinging |
5.80 |
2.32 |
6.07 |
6.1 |
Slider |
79.96 |
2343.46 |
111.39 |
-6.18 |
3.70 |
StrikeCalled |
5.60 |
2.79 |
5.42 |
3.7 |
Slider |
79.91 |
2420.65 |
111.03 |
-5.45 |
3.48 |
StrikeCalled |
5.70 |
2.83 |
5.41 |
3.7 |
Four-Seam |
87.63 |
2305.76 |
192.53 |
3.80 |
18.17 |
StrikeSwinging |
5.75 |
2.44 |
5.99 |
6.4 |
Cutter |
83.44 |
2277.34 |
190.89 |
3.40 |
18.92 |
BallCalled |
5.88 |
2.48 |
5.86 |
6.4 |
Cutter |
83.90 |
2194.74 |
198.26 |
4.31 |
14.39 |
InPlay |
5.94 |
2.27 |
5.94 |
6.6 |
Four-Seam |
85.60 |
2255.79 |
191.47 |
3.91 |
20.56 |
BallCalled |
5.92 |
2.43 |
6.25 |
6.4 |
Slider |
78.19 |
2329.83 |
109.32 |
-13.51 |
6.35 |
BallCalled |
5.78 |
2.64 |
5.35 |
3.6 |
Slider |
83.46 |
2279.34 |
198.21 |
3.15 |
10.83 |
BallCalled |
5.87 |
2.44 |
5.97 |
6.6 |
Cutter |
85.23 |
2243.95 |
179.46 |
-0.15 |
16.76 |
BallCalled |
5.82 |
2.29 |
5.96 |
6.0 |
Cutter |
84.14 |
2222.65 |
195.70 |
4.04 |
15.71 |
BallCalled |
5.92 |
2.37 |
6.00 |
6.5 |
Cutter |
83.97 |
2204.67 |
189.69 |
3.14 |
19.79 |
BallCalled |
5.89 |
2.18 |
6.07 |
6.3 |
Changeup |
84.19 |
2294.10 |
221.44 |
10.19 |
12.78 |
FoulBallNotFieldable |
5.81 |
2.45 |
5.88 |
7.4 |
Slider |
77.58 |
2351.37 |
127.20 |
-11.11 |
10.18 |
FoulBallNotFieldable |
5.73 |
2.75 |
5.28 |
4.2 |
Slider |
76.92 |
2321.64 |
105.50 |
-17.25 |
6.50 |
BallCalled |
5.74 |
2.54 |
5.30 |
3.5 |
Four-Seam |
83.89 |
2185.63 |
202.10 |
6.22 |
16.66 |
BallCalled |
5.83 |
2.48 |
5.99 |
6.7 |
# 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: 24
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Tommy Flaherty")
Summary Pitch Table for Tommy Flaherty
Changeup |
4.17% |
1 |
0 |
1 |
0.00% |
100.00% |
84.19 |
2294.10 |
12.78 |
10.19 |
221.44 |
7.4 |
5.81 |
2.45 |
5.88 |
Cutter |
20.83% |
5 |
4 |
1 |
80.00% |
20.00% |
84.14 |
2228.67 |
17.11 |
2.95 |
190.80 |
6.4 |
5.89 |
2.32 |
5.97 |
Four-Seam |
37.50% |
9 |
5 |
4 |
55.56% |
44.44% |
86.64 |
2279.15 |
17.36 |
4.06 |
194.38 |
6.5 |
5.81 |
2.39 |
6.10 |
Slider |
37.50% |
9 |
3 |
6 |
33.33% |
66.67% |
79.36 |
2374.61 |
5.41 |
-8.87 |
115.95 |
3.8 |
5.74 |
2.64 |
5.45 |
# 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("Tommy Flaherty maximum FB velocity: ", max_fb_velocity, "mph\n")
## Tommy Flaherty maximum FB velocity: 87.9 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 Tommy Flaherty",
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")
)
