passes <- read.csv("kondo.csv")
This document is a quick tutorial on how to create a simple pass-map for soccer. It is important to not that although this specific document focuses on soccer, it can be easily recreated for different sports as long as there is X, Y, endX and endY data.
library(ggsoccer)
## Warning: package 'ggsoccer' was built under R version 4.2.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
As mentioned the data must have X, Y , endX and endY coordinates, for soccer coordinates can plotted using Ben Torvaneys Soccer event logger: https://torvaney.github.io/projects/tracker.html.
##Code - Creating Soccer Pitch The following is just creating the pitch, without any passes plotted (my dataframe was named passes).
ggplot(passes) +
annotate_pitch(colour = "white",
fill = "#3ab54a")
##Now adding the passes
ggplot(passes) +
annotate_pitch(colour = "white",
fill = "#3ab54a") +
geom_segment(aes(x = x, y = y, xend = endX, yend = endY),
arrow = arrow(length = unit(0.2 , "cm"),
type = "closed"))
##Last Step The last step of the pass map is filling out the pitch so there is no grid around it
ggplot(passes) +
annotate_pitch(colour = "white",
fill = "#3ab54a") +
geom_segment(aes(x = x, y = y, xend = endX, yend = endY),
arrow = arrow(length = unit(0.2 , "cm"),
type = "closed")) +
theme_pitch() +
theme(panel.background = element_rect(fill = "#3ab54a")) +
ggtitle("Goalkeeper Passmap")