Skip to content

Instantly share code, notes, and snippets.

@AlienDeg
Created December 27, 2021 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlienDeg/cd7d3a1a2e88495caf80a19d32148d45 to your computer and use it in GitHub Desktop.
Save AlienDeg/cd7d3a1a2e88495caf80a19d32148d45 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(StatsBombR)
library(ggtext)
library(scales)
library(bbplot)
library(extrafont)
library(ggforce)
library(ggrepel)
library(png)
library(grid)
events<- #get your statsbomb events data here
to_plot <- events %>% filter(pass.type.name == 'Goal Kick') %>%
group_by(team.name, team.id) %>%
summarise(pass_length = mean(pass.length, na.rm=TRUE),
accuracy = sum(is.na(pass.outcome.id))/n(),
cnt= n(),
accurate_passes = sum(is.na(pass.outcome.id)))
%>% ungroup()
img <- readPNG("ekstraklasa.png",TRUE)
g <- rasterGrob(img, interpolate=TRUE)
ggplot(to_plot) +
geom_arc(aes(x0=(pass_length/2), y0=1, r=pass_length/2, start=-1.57,end=1.57, color=accuracy),
size=1.4) +
geom_text_repel(aes(x=pass_length+1, y=0, label=team.name),
angle=315, size=2.5, direction = 'x', box.padding=0, family='sans') +
theme(
axis.title.y = element_blank(),
plot.caption = element_text(
size = 13,
hjust = 0.5,
vjust = 0.5
),
plot.subtitle = element_text(
size = 18,
hjust = 0.5
),
axis.text.y = element_blank(),
legend.title=element_text(size=14),
legend.text = element_text(size = 14),
legend.key.size = unit(1.5, "cm"),
plot.title = element_textbox_simple(
size = 21,
lineheight = 1,
family='sans',
padding = margin(5.5, 5.5, 5.5, 5.5),
margin = margin(0, 0, 5.5, 0)
),
legend.direction = "vertical",
axis.ticks = element_blank(),
plot.background = element_rect(fill = "white"),
strip.text.x = element_text(size = 13),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(),
legend.background = element_blank(),
legend.box.background = element_blank(),
legend.key = element_rect(fill = "white",
colour = NA)
) +
labs(title = "<b>Goalkicks in Ekstraklasa</b><br>
<span style='font-size:10pt'>Average lenght and accuracy of goalkicks | Season 21-22 | Data: Statsbomb | By: @AlienPawi | Viz idea: @Odriozolite </span>", x='Pass Length') +
annotation_custom(g, xmin=55, xmax=65, ymin=0, ymax=60) +
scale_color_gradientn(colors=met.brewer("Hokusai2", n=10))
ggsave(filename='plot.png',height = 5, widt = 10, dpi=600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment