Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -1631,51 +1631,6 @@ create_pitcher_release_plot <- function(game_data, pitch_colors) {
|
|
| 1631 |
theme(legend.position = "none")
|
| 1632 |
}
|
| 1633 |
|
| 1634 |
-
create_extension_height_plot <- function(data, player_name, pitch_colors) {
|
| 1635 |
-
data <- normalize_columns(data)
|
| 1636 |
-
|
| 1637 |
-
pitcher_data <- data %>%
|
| 1638 |
-
filter(Pitcher == player_name,
|
| 1639 |
-
!is.na(TaggedPitchType),
|
| 1640 |
-
TaggedPitchType != "Other",
|
| 1641 |
-
!is.na(Extension),
|
| 1642 |
-
!is.na(RelHeight))
|
| 1643 |
-
|
| 1644 |
-
if (nrow(pitcher_data) == 0) {
|
| 1645 |
-
return(ggplot() + theme_void() + ggtitle("Extension vs Release Height") +
|
| 1646 |
-
theme(plot.title = element_text(size = 12, face = "bold", hjust = 0.5)))
|
| 1647 |
-
}
|
| 1648 |
-
|
| 1649 |
-
avg_release <- pitcher_data %>%
|
| 1650 |
-
group_by(TaggedPitchType) %>%
|
| 1651 |
-
summarise(
|
| 1652 |
-
Extension = mean(Extension, na.rm = TRUE),
|
| 1653 |
-
RelHeight = mean(RelHeight, na.rm = TRUE),
|
| 1654 |
-
.groups = "drop"
|
| 1655 |
-
)
|
| 1656 |
-
|
| 1657 |
-
ggplot(pitcher_data, aes(Extension, RelHeight)) +
|
| 1658 |
-
geom_point(aes(fill = TaggedPitchType),
|
| 1659 |
-
size = 4, shape = 21, color = "black", alpha = 0.85, stroke = 0.25) +
|
| 1660 |
-
geom_point(data = avg_release,
|
| 1661 |
-
aes(Extension, RelHeight, fill = TaggedPitchType),
|
| 1662 |
-
size = 4.5, shape = 21, color = "black", stroke = 0.3, alpha = 1) +
|
| 1663 |
-
annotate("text", x = 1, y = 8, label = "\u2190 2B", size = 3, hjust = 0) +
|
| 1664 |
-
annotate("text", x = 8, y = 8, label = "Home \u2192", size = 3, hjust = 1) +
|
| 1665 |
-
geom_rect(aes(xmin = 0, xmax = 2.7, ymin = 0, ymax = 0.83),
|
| 1666 |
-
fill = "#632b11", inherit.aes = FALSE) +
|
| 1667 |
-
geom_rect(aes(xmin = -0.5, xmax = 1, ymin = 0.8, ymax = 0.95),
|
| 1668 |
-
fill = "white", color = "black", linewidth = 0.4, inherit.aes = FALSE) +
|
| 1669 |
-
geom_vline(xintercept = 5.6, linetype = "dashed", linewidth = 0.4, color = "grey20") +
|
| 1670 |
-
geom_hline(yintercept = 5.8, linetype = "dashed", linewidth = 0.4, color = "grey20") +
|
| 1671 |
-
scale_fill_manual(values = pitch_colors, name = "Pitch Type") +
|
| 1672 |
-
coord_cartesian(xlim = c(1, 8), ylim = c(0, 8)) +
|
| 1673 |
-
labs(title = "Release Height + Extension (Dashed = SEC Avg)",
|
| 1674 |
-
x = "Extension (ft)", y = "Release Height (ft)") +
|
| 1675 |
-
theme_minimal() +
|
| 1676 |
-
theme(plot.title = element_text(hjust = 0.5, size = 10, face = "bold"),
|
| 1677 |
-
legend.position = "none")
|
| 1678 |
-
}
|
| 1679 |
|
| 1680 |
create_relside_height_plot <- function(data, player_name, pitch_colors) {
|
| 1681 |
data <- normalize_columns(data)
|
|
@@ -1712,11 +1667,9 @@ create_relside_height_plot <- function(data, player_name, pitch_colors) {
|
|
| 1712 |
fill = "#632b11", inherit.aes = FALSE) +
|
| 1713 |
geom_rect(aes(xmin = -0.7, xmax = 0.7, ymin = 0.8, ymax = 0.95),
|
| 1714 |
fill = "white", color = "black", linewidth = 0.4, inherit.aes = FALSE) +
|
| 1715 |
-
geom_vline(xintercept = 1.9, linetype = "dashed", linewidth = 0.4, color = "grey20") +
|
| 1716 |
-
geom_hline(yintercept = 5.7, linetype = "dashed", linewidth = 0.4, color = "grey20") +
|
| 1717 |
scale_fill_manual(values = pitch_colors, name = "Pitch Type") +
|
| 1718 |
coord_cartesian(xlim = c(-5, 5), ylim = c(0, 8)) +
|
| 1719 |
-
labs(title = "Release Height + Release Side
|
| 1720 |
x = "Release Side (ft)", y = "Release Height (ft)") +
|
| 1721 |
theme_minimal() +
|
| 1722 |
theme(plot.title = element_text(hjust = 0.5, size = 10, face = "bold"),
|
|
@@ -3270,11 +3223,6 @@ create_advanced_pitcher_pdf <- function(game_df, pitcher_name, output_file) {
|
|
| 3270 |
tryCatch(print(count_plot, newpage = FALSE), error = function(e) NULL)
|
| 3271 |
grid::popViewport()
|
| 3272 |
|
| 3273 |
-
# Extension vs Height (top right of row 2)
|
| 3274 |
-
grid::pushViewport(grid::viewport(x = 0.77, y = count_y_top, width = 0.42, height = count_height * 0.5, just = c("center","top")))
|
| 3275 |
-
tryCatch(print(extension_height_plot, newpage = FALSE), error = function(e) NULL)
|
| 3276 |
-
grid::popViewport()
|
| 3277 |
-
|
| 3278 |
# RelSide vs Height (bottom right of row 2)
|
| 3279 |
grid::pushViewport(grid::viewport(x = 0.77, y = count_y_top - count_height * 0.5, width = 0.42, height = count_height * 0.5, just = c("center","top")))
|
| 3280 |
tryCatch(print(relside_height_plot, newpage = FALSE), error = function(e) NULL)
|
|
|
|
| 1631 |
theme(legend.position = "none")
|
| 1632 |
}
|
| 1633 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1634 |
|
| 1635 |
create_relside_height_plot <- function(data, player_name, pitch_colors) {
|
| 1636 |
data <- normalize_columns(data)
|
|
|
|
| 1667 |
fill = "#632b11", inherit.aes = FALSE) +
|
| 1668 |
geom_rect(aes(xmin = -0.7, xmax = 0.7, ymin = 0.8, ymax = 0.95),
|
| 1669 |
fill = "white", color = "black", linewidth = 0.4, inherit.aes = FALSE) +
|
|
|
|
|
|
|
| 1670 |
scale_fill_manual(values = pitch_colors, name = "Pitch Type") +
|
| 1671 |
coord_cartesian(xlim = c(-5, 5), ylim = c(0, 8)) +
|
| 1672 |
+
labs(title = "Release Height + Release Side",
|
| 1673 |
x = "Release Side (ft)", y = "Release Height (ft)") +
|
| 1674 |
theme_minimal() +
|
| 1675 |
theme(plot.title = element_text(hjust = 0.5, size = 10, face = "bold"),
|
|
|
|
| 3223 |
tryCatch(print(count_plot, newpage = FALSE), error = function(e) NULL)
|
| 3224 |
grid::popViewport()
|
| 3225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3226 |
# RelSide vs Height (bottom right of row 2)
|
| 3227 |
grid::pushViewport(grid::viewport(x = 0.77, y = count_y_top - count_height * 0.5, width = 0.42, height = count_height * 0.5, just = c("center","top")))
|
| 3228 |
tryCatch(print(relside_height_plot, newpage = FALSE), error = function(e) NULL)
|