Packages

pacman::p_load(tidyverse,cowplot,magick,extrafont,gt,janitor)

Data

df <- read.csv("C:\\Users\\danni\\OneDrive\\Documents\\20220423-Olsen-1.csv", header = T)

Pitch Type Counts

#Counts of each pitch type for each pitcher
count_pt <-df %>%
  group_by(Pitcher,TaggedPitchType) %>%
  summarise(Count=n())

gt_count_pt<- count_pt %>%
  pivot_wider(names_from= TaggedPitchType, values_from=Count) %>%
  tibble::column_to_rownames('Pitcher') %>%
  replace(is.na(.), 0) %>%
  gt::gt(rownames_to_stub = TRUE) %>%
  tab_header(
    title = 'Pitch Type Counts for Each Pitcher',
    subtitle = 'Arkansas vs Texas 4/23/22'
  ) %>%
  gtExtras::gt_highlight_rows(
    row = 1,
    fill = "#9D2235",
    bold_target_only = TRUE
  ) %>%
  gtExtras::gt_theme_espn()
  
  
  

gt_count_pt
Pitch Type Counts for Each Pitcher
Arkansas vs Texas 4/23/22
ChangeUp Fastball Slider Curveball
Dallas, Micah 4 25 39 0
Menefee, Joseph 0 38 27 0
Morris, Zack 13 18 3 21
Smith, Hagen 10 54 6 0
Taylor, Evan 1 10 7 0
Tucker, Wyatt 4 5 7 0
Tygart, Brady 0 4 4 4
Vermillion, Zebulon 0 9 0 1

BarPlot for Counts

p_type <- ggplot(count_pt, aes(x=Pitcher, y=Count)) +
  geom_bar( stat = 'identity',
            aes(fill=TaggedPitchType)) +
  scale_fill_manual(values=c("#9D2235",
                             "#FFFFFF",
                             "#500000",
                             "#E59E6D")) +
  scale_y_continuous(limits=c(0,80)) +
  labs(title = "Pitch Type Counts",
       subtitle = "Arkansas vs. Texas || April 23, 2022",
       x = "Pitcher",
       y = "Count") +
  geom_text(aes(label=Count, group=TaggedPitchType, fontface="bold"), position= position_stack(vjust=.5)) +
  theme(
    # labels/text
    plot.title = element_text(hjust = .5, size = 20, family = "Garamond", face = "bold", color = "white"),
    plot.subtitle = element_text(hjust = .5, size = 12, family = "Garamond", color = "white"),
    text = element_text(family = "Garamond"),
    # plot background and lines
    plot.background = element_rect(fill="gray15", color = "gray15"),
    panel.background = element_rect(fill="gray15", color = "gray15"),
    panel.grid.minor.y = element_blank(),
    panel.grid.major.y = element_line(colour = "gray20"),
    panel.grid.major.x = element_blank(),
    axis.line = element_line(colour = "white"),
    legend.position = c(.9,.7),
    legend.background = element_blank(),
    legend.text = element_text(hjust = .10, size = 10, family = "Garamond", face = "bold", colour = "white"),
    legend.title = element_text(family = "Garamond", face = "bold",colour='white'),
    # axis
    axis.title.x = element_text(colour = "white", size = 14, face = "bold"),
    axis.title.y = element_text(colour = "white", size = 14,face = "bold"),
    axis.text.x = element_text(colour = "white", size = 10, face = "bold"),
    axis.text.y = element_text(colour = "white", size = 10, face = "bold"))


  ggdraw(p_type)+
    draw_image('https://arkansasrazorbacks.com/wp-content/uploads/2022/09/Running-Razorback_FC-300x180.png',
               x=.20,y=.89 ,height=.12, width=.12) +
    draw_image('https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/245.png&h=208&w=208', x=.73,y=.89 ,height=.12, width=.12)

Miach Dallas’ Release Pitch Speeds

#Getting All Dallas' Pitches
dallas_p <- df %>%
  filter(Pitcher == "Dallas, Micah")

# Box Plot
d_speed <- ggplot(dallas_p, aes(x=TaggedPitchType, y=RelSpeed,color= TaggedPitchType)) +
  geom_boxplot(outlier.colour = "white", outlier.shape = 1) +
  labs(title = "Release Speed of Each Pitch Type for Miach Dallas",
      subtitle = "Arkansas vs. Texas || April 23, 2022",
      x = "TaggedPitchType",
       y = "Release Speed")+
  theme(
    # labels/text
    plot.title = element_text(hjust = .1, size = 20, family = "Garamond", face = "bold", color = "white"),
    plot.subtitle = element_text(hjust = .5, size = 12, family = "Garamond", color = "white"),
    text = element_text(family = "Garamond"),
    # plot background and lines
    plot.background = element_rect(fill="gray15", color = "gray15"),
    panel.background = element_rect(fill="gray15", color = "gray15"),
    panel.grid.minor.y = element_blank(),
    panel.grid.major.y = element_line(colour = "white"),
    panel.grid.major.x = element_blank(),
    axis.line = element_line(colour = "white"),
    #legend.position = c(.9,.7),
    legend.background = element_blank(),
    legend.text = element_text(hjust = .10, size = 10, family = "Garamond", face = "bold", colour = "white"),
    legend.title = element_text(family = "Garamond", face = "bold",colour='white'),
    # axis
    axis.title.x = element_text(colour = "white", size = 14, face = "bold"),
    axis.title.y = element_text(colour = "white", size = 14,face = "bold"),
    axis.text.x = element_text(colour = "white", size = 10, face = "bold"),
    axis.text.y = element_text(colour = "white", size = 10, face = "bold"))

ggdraw(d_speed)+
  draw_image('https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/245.png&h=208&w=208', x=.85,y=.80,height=.14, width=.14)

Miach Dallas’ Pitch Movement

#ScatterPlot
p_move <-ggplot(dallas_p,aes(x=HorzBreak, y=InducedVertBreak, color = TaggedPitchType)) +
  geom_point()+
  lims(x=c(-20,20),y=c(-25,25)) +
  coord_fixed() +  
  geom_vline(xintercept = 0) + geom_hline(yintercept = 0) +
  labs(title = "Pitch Movement for Miach Dallas",
       subtitle = "Arkansas vs. Texas || April 23, 2022",
       x = "Horizontal Break",
       y = "Induced Vertical Break")+
  theme(
    # labels/text
    plot.title = element_text(hjust = .1, size = 20, family = "Garamond", face = "bold", color = "white"),
    plot.subtitle = element_text(hjust = .5, size = 12, family = "Garamond", color = "white"),
    text = element_text(family = "Garamond"),
    # plot background and lines
    plot.background = element_rect(fill="gray15", color = "gray15"),
    panel.background = element_rect(fill="gray15", color = "gray15"),
    panel.grid.minor.y = element_line(colour = "gray20"),
    panel.grid.major.y = element_line(colour = "gray20"),
    panel.grid.major.x = element_line(colour = "gray20"),
    panel.grid.minor.x = element_line(colour='gray20'),
    axis.line = element_line(colour = "white"),
    #legend.position = c(.9,.7),
    legend.background = element_blank(),
    legend.text = element_text(hjust = .10, size = 10, family = "Garamond", face = "bold", colour = "white"),
    legend.title = element_text(family = "Garamond", face = "bold",colour='white'),
    # axis
    axis.title.x = element_text(colour = "white", size = 14, face = "bold"),
    axis.title.y = element_text(colour = "white", size = 14,face = "bold"),
    axis.text.x = element_text(colour = "white", size = 10, face = "bold"),
    axis.text.y = element_text(colour = "white", size = 10, face = "bold"))

ggdraw(p_move)+
draw_image('https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/245.png&h=208&w=208',x=.64,y=.77 ,height=.14, width=.14)