Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -557,24 +557,45 @@ catcher_create_framing_plots <- function(catcher_data, catcher_name) {
|
|
| 557 |
"Fastball"="#FA8072","Four-Seam"="#FA8072","Sinker"="#fdae61","Slider"="#A020F0",
|
| 558 |
"Sweeper"="magenta","Curveball"="#2c7bb6","ChangeUp"="#90EE90","Splitter"="#90EE32","Cutter"="red"
|
| 559 |
)
|
| 560 |
-
|
| 561 |
-
if (!nrow(data)) return(ggplot() + theme_void() + ggtitle(title))
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
annotate("
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
}
|
| 576 |
-
|
| 577 |
-
|
|
|
|
|
|
|
|
|
|
| 578 |
}
|
| 579 |
|
| 580 |
catcher_create_framing_plot <- function(catcher_data, catcher_name) {
|
|
|
|
| 557 |
"Fastball"="#FA8072","Four-Seam"="#FA8072","Sinker"="#fdae61","Slider"="#A020F0",
|
| 558 |
"Sweeper"="magenta","Curveball"="#2c7bb6","ChangeUp"="#90EE90","Splitter"="#90EE32","Cutter"="red"
|
| 559 |
)
|
| 560 |
+
make_plot <- function(data, title, show_legend = FALSE){
|
| 561 |
+
if (!nrow(data)) return(ggplot2::ggplot() + ggplot2::theme_void() + ggplot2::ggtitle(title))
|
| 562 |
+
|
| 563 |
+
gg <- ggplot2::ggplot(data, ggplot2::aes(PlateLocSide, PlateLocHeight)) +
|
| 564 |
+
# strike zone
|
| 565 |
+
ggplot2::annotate("rect",
|
| 566 |
+
xmin = zone$xmin, xmax = zone$xmax,
|
| 567 |
+
ymin = zone$ymin, ymax = zone$ymax,
|
| 568 |
+
fill = NA, color = "black", size = 0.5
|
| 569 |
+
) +
|
| 570 |
+
# home plate (your original, lowered)
|
| 571 |
+
ggplot2::annotate("segment", x=-0.708, y=0.05, xend=0.708, yend=0.05, size=0.5, color="black") +
|
| 572 |
+
ggplot2::annotate("segment", x=-0.708, y=0.20, xend=-0.708, yend=0.05, size=0.5, color="black") +
|
| 573 |
+
ggplot2::annotate("segment", x= 0.708, y=0.20, xend= 0.708, yend=0.05, size=0.5, color="black") +
|
| 574 |
+
ggplot2::annotate("segment", x=-0.708, y=0.20, xend=0, yend=0.40, size=0.5, color="black") +
|
| 575 |
+
ggplot2::annotate("segment", x= 0.708, y=0.20, xend=0, yend=0.40, size=0.5, color="black") +
|
| 576 |
+
# pitches
|
| 577 |
+
ggplot2::geom_point(ggplot2::aes(color = TaggedPitchType), size = 3, alpha = 0.95, na.rm = TRUE) +
|
| 578 |
+
ggplot2::scale_color_manual(values = pitch_colors, na.value = "grey60", name = "Pitch Type") +
|
| 579 |
+
ggplot2::coord_fixed() +
|
| 580 |
+
ggplot2::xlim(-2, 2) + ggplot2::ylim(0, 4) +
|
| 581 |
+
ggplot2::labs(title = title) +
|
| 582 |
+
ggplot2::theme_void() +
|
| 583 |
+
ggplot2::theme(
|
| 584 |
+
plot.title = ggplot2::element_text(size = 11, face = "bold", hjust = 0.5),
|
| 585 |
+
legend.position = if (show_legend) "bottom" else "none",
|
| 586 |
+
legend.title = ggplot2::element_text(size = 9, face = "bold"),
|
| 587 |
+
legend.text = ggplot2::element_text(size = 8),
|
| 588 |
+
legend.key.size = ggplot2::unit(0.5, "lines"),
|
| 589 |
+
legend.box = "horizontal"
|
| 590 |
+
)
|
| 591 |
+
|
| 592 |
+
gg
|
| 593 |
}
|
| 594 |
+
|
| 595 |
+
list(
|
| 596 |
+
p1 = make_plot(strikes_added, "Strikes Stolen", show_legend = FALSE),
|
| 597 |
+
p2 = make_plot(strikes_lost, "Strikes Lost", show_legend = TRUE) # legend shown once
|
| 598 |
+
)
|
| 599 |
}
|
| 600 |
|
| 601 |
catcher_create_framing_plot <- function(catcher_data, catcher_name) {
|