# Filter the data for the pitcher Tyler Cox
Brian_Foley_data <- data %>%
filter(Pitcher == "Cox, Tyler")
# 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 Tyler Cox")
Detailed Pitch Table for Tyler Cox
Sinker |
87.34 |
2001.24 |
244.07 |
18.04 |
10.13 |
StrikeCalled |
4.86 |
2.01 |
5.85 |
8.1 |
Changeup |
78.14 |
1985.81 |
268.19 |
23.24 |
2.42 |
InPlay |
4.87 |
2.12 |
5.58 |
8.9 |
Sinker |
87.07 |
2071.39 |
232.70 |
16.06 |
13.68 |
StrikeCalled |
4.93 |
1.94 |
6.13 |
7.8 |
Curveball |
72.77 |
1995.08 |
51.02 |
-14.97 |
-10.17 |
StrikeCalled |
5.18 |
1.84 |
5.29 |
1.7 |
Curveball |
76.54 |
2090.50 |
108.10 |
-9.39 |
5.04 |
BallCalled |
4.96 |
1.92 |
5.51 |
3.6 |
Sinker |
87.72 |
2016.42 |
235.45 |
16.64 |
12.86 |
InPlay |
5.03 |
1.90 |
6.16 |
7.8 |
Sinker |
87.47 |
2023.79 |
240.71 |
16.84 |
10.83 |
StrikeCalled |
4.95 |
1.93 |
6.07 |
8.0 |
Curveball |
73.77 |
2075.83 |
53.28 |
-16.99 |
-10.62 |
InPlay |
5.27 |
1.73 |
5.06 |
1.8 |
Changeup |
86.85 |
1914.31 |
220.46 |
11.10 |
14.29 |
BallCalled |
4.97 |
1.92 |
5.98 |
7.3 |
Changeup |
87.03 |
2063.97 |
244.58 |
16.79 |
9.24 |
BallCalled |
5.10 |
2.02 |
5.82 |
8.2 |
Sinker |
86.84 |
2014.86 |
223.19 |
12.25 |
14.29 |
FoulBallNotFieldable |
5.02 |
2.01 |
5.92 |
7.4 |
Changeup |
85.31 |
1883.17 |
269.20 |
17.62 |
1.50 |
FoulBallNotFieldable |
4.97 |
1.91 |
6.01 |
9.0 |
Changeup |
77.48 |
1977.93 |
271.69 |
22.50 |
1.20 |
InPlay |
4.91 |
2.07 |
5.54 |
9.1 |
Sinker |
86.58 |
2076.18 |
235.95 |
17.59 |
13.20 |
StrikeCalled |
5.12 |
2.13 |
5.83 |
7.9 |
Sinker |
87.05 |
2073.92 |
236.13 |
18.06 |
13.45 |
StrikeSwinging |
5.17 |
2.13 |
5.76 |
7.9 |
Changeup |
77.27 |
1949.18 |
269.52 |
20.40 |
1.82 |
FoulBallNotFieldable |
4.99 |
2.00 |
5.70 |
9.0 |
Curveball |
73.42 |
1884.54 |
53.08 |
-18.09 |
-11.85 |
StrikeSwinging |
5.51 |
1.85 |
5.32 |
1.8 |
Sinker |
86.71 |
2102.68 |
237.44 |
17.93 |
12.74 |
FoulBallNotFieldable |
5.19 |
2.06 |
5.84 |
7.9 |
Changeup |
77.03 |
1904.74 |
284.93 |
17.11 |
-2.93 |
InPlay |
5.11 |
2.21 |
5.46 |
9.5 |
Curveball |
74.61 |
1862.79 |
51.16 |
-15.80 |
-11.02 |
StrikeCalled |
5.12 |
1.75 |
5.58 |
1.7 |
Curveball |
74.67 |
1855.59 |
51.99 |
-16.00 |
-10.79 |
InPlay |
5.22 |
1.85 |
5.44 |
1.7 |
Sinker |
88.81 |
2028.25 |
226.51 |
14.42 |
14.96 |
StrikeCalled |
5.00 |
1.87 |
6.18 |
7.6 |
Changeup |
78.16 |
1914.16 |
268.73 |
17.52 |
2.08 |
InPlay |
4.95 |
1.94 |
5.68 |
9.0 |
Curveball |
73.41 |
1909.36 |
55.07 |
-17.21 |
-10.23 |
StrikeCalled |
5.20 |
1.73 |
5.52 |
1.8 |
Sinker |
88.06 |
2074.46 |
239.75 |
17.08 |
11.27 |
StrikeCalled |
4.96 |
1.86 |
6.07 |
8.0 |
Curveball |
75.33 |
2004.68 |
49.41 |
-16.55 |
-12.37 |
InPlay |
5.37 |
1.62 |
5.10 |
1.6 |
# 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: 26
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Tyler Cox")
Summary Pitch Table for Tyler Cox
Changeup |
30.77% |
8 |
2 |
6 |
25.00% |
75.00% |
80.91 |
1949.16 |
3.70 |
18.28 |
262.16 |
8.8 |
4.98 |
2.02 |
5.72 |
Curveball |
30.77% |
8 |
1 |
7 |
12.50% |
87.50% |
74.32 |
1959.80 |
-9.00 |
-15.62 |
59.14 |
2.0 |
5.23 |
1.79 |
5.35 |
Sinker |
38.46% |
10 |
0 |
10 |
0.00% |
100.00% |
87.36 |
2048.32 |
12.74 |
16.49 |
235.19 |
7.8 |
5.02 |
1.98 |
5.98 |
# 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("Tyler Cox maximum FB velocity: ", max_fb_velocity, "mph\n")
## Tyler Cox maximum FB velocity: 88.81 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.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 Tyler Cox",
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")
)
