igroffman commited on
Commit
b96de6c
·
verified ·
1 Parent(s): 19a9af2

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +38 -17
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
- make_plot <- function(data, title){
561
- if (!nrow(data)) return(ggplot() + theme_void() + ggtitle(title))
562
- ggplot(data, aes(PlateLocSide, PlateLocHeight)) +
563
- annotate("rect", xmin=-0.83, xmax=0.83, ymin=1.5, ymax=3.3775, alpha=0, size=.5, color="black") +
564
- annotate("segment", x=-0.708,y=0.15,xend=0.708,yend=0.15, size=.5, color="black") +
565
- annotate("segment", x=-0.708,y=0.3,xend=-0.708,yend=0.15, size=.5, color="black") +
566
- annotate("segment", x= 0.708,y=0.3,xend= 0.708,yend=0.15, size=.5, color="black") +
567
- annotate("segment", x=-0.708,y=0.3,xend=0,yend=0.5, size=.5, color="black") +
568
- annotate("segment", x= 0.708,y=0.3,xend=0,yend=0.5, size=.5, color="black") +
569
- geom_point(aes(color=TaggedPitchType), size=3, alpha=.95) +
570
- scale_color_manual(values=pitch_colors, na.value="grey60") +
571
- xlim(-2,2) + ylim(0,4) + coord_fixed() +
572
- labs(color="", title=title) + theme_void() +
573
- theme(plot.title=element_text(size=11, face="bold", hjust=.5),
574
- legend.position="none")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  }
576
- list(p1 = make_plot(strikes_added, "Strikes Stolen"),
577
- p2 = make_plot(strikes_lost, "Strikes Lost"))
 
 
 
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) {