Visualizing Sports Data with sportyR

Graham Medairy

Sports Data Needs Context

SportyR at a Glance?

  • Draws accurate, scaled sports fields in R

  • Built on ggplot2, so you can layer your own data

  • Ideal for spray charts, shot charts, heatmaps, and tracking data

  • Supports multiple sports: baseball, football, soccer, basketball, hockey

Seeing the Field

  • SportyR uses simple geoms to generate fields

Infield vs Full-Field Views

  • You can control how much of the field is shown.

Changing the size

library(sportyR)
geom_baseball("mlb", display_range = "full") 

Cross-Sport Flexibility

  • Same syntax, different sports

How sportyR Fits into ggplot2

  • Each sport has its own geom_*() function

  • Fields act as base layers in a ggplot

  • You add points, heatmaps, or paths on top

Real Analytics Use Cases

  • Analyze where hits land

  • Compare hits vs outs

spray_plot <- 
  geom_baseball("mlb") +
  ggplot2::labs(
    title = "MLB Baseball Field",
    x = 'ft',
    y = 'ft'
  )+
  geom_point(
    data = ff,
    aes(x = location_x, y = location_y, color = H),
    size = 3, alpha = 0.9
  ) +
  scale_colour_manual(values = c("Out" = "red", "Hit" = "blue")) +
  coord_fixed(
    xlim = c(x_min, x_max),
    ylim = c(y_min, y_max)
  )

Using SportyR with the Spray data

Resources & Documentation

👨‍💻Contact

<Graham Medairy>
Email: <Graham_medairy1@baylor.edu>