Here I have just used some data I prepared to look at attacking statistics for attackers and defenders going into the final week of the Premier League!
# Packages
library(tidyverse)
library(extrafont)
library(ggrepel)
library(dplyr)
library(ggimage)
library(Metrics)
# Get data
PlayerData <- read.csv('/Users/alicesmail/Desktop/Programming/GitHubPage/FPL/Projects/Best Predictors/Best-Predictors-24-25-Output/FullPlayerData.csv') %>% unique() %>% replace(is.na(.), 0)
# Plot xG vs opponent xGC
ggplot(PlayerData%>%filter((position=='MID'|position=='FWD'), gameweek==38, xG90>0.1, meanMinutes>45),
aes(x=xG90+xA90, y=opp_mean_xGC, colour=team_colour1, label=web_name, size=points90))+
geom_jitter(alpha=0.1)+
ggrepel::geom_text_repel(colour='black', nudge_y=0, family='Radio Canada Big', size=4, fontface='bold', min.segment.length=5)+
scale_colour_identity()+
theme_classic()+
theme(text=element_text(family='Radio Canada Big', size=15),
axis.ticks=element_blank(),
panel.grid.major=element_line(colour='lightgrey', linetype='dashed'),
panel.grid.minor=element_blank(),
panel.border=element_blank(),
plot.background=element_rect(fill='#feffeb'),
panel.background=element_rect(fill='#feffeb'),
legend.background=element_rect(fill='#feffeb'),
plot.title=element_text(hjust=0, face='bold', size=20),
plot.subtitle=element_text(hjust=0, size=12))+
guides(fill='none')+
guides(colour='none', size='none')+
scale_size_continuous(range=c(5,30))+
labs(y='Mean Opposition xGC')+
scale_y_continuous(expand=c(0.05,0.05))+
scale_x_continuous(expand=c(0.05,0.05))+
labs(title='Attacking Stats Last 6 Weeks',
subtitle='Expected goal involvement vs mean opponent team expected goals conceded over previous 6 weeks')
# Plot xGI vs opponent xG
ggplot(PlayerData%>%filter((position=='DEF'), gameweek==38, xG90+xA90>0.05, meanMinutes>45),
aes(x=xG90+xA90, y=opp_mean_xG, colour=team_colour1, label=web_name, size=points90))+
geom_jitter(alpha=0.1)+
ggrepel::geom_text_repel(colour='black', nudge_y=0, family='Radio Canada Big', size=4, fontface='bold', min.segment.length=5)+
scale_colour_identity()+
theme_classic()+
theme(text=element_text(family='Radio Canada Big', size=15),
axis.ticks=element_blank(),
panel.grid.major=element_line(colour='lightgrey', linetype='dashed'),
panel.grid.minor=element_blank(),
panel.border=element_blank(),
plot.background=element_rect(fill='#feffeb'),
panel.background=element_rect(fill='#feffeb'),
legend.background=element_rect(fill='#feffeb'),
plot.title=element_text(hjust=0, face='bold', size=20),
plot.subtitle=element_text(hjust=0, size=12))+
guides(fill='none')+
guides(colour='none', size='none')+
scale_size_continuous(range=c(5,30))+
labs(y='Mean Opposition xG')+
scale_y_continuous(expand=c(0.05,0.05), trans="reverse")+
scale_x_continuous(expand=c(0.05,0.05))+
labs(title='Defender Attacking Stats Last 6 Weeks',
subtitle='Expected goal involvement vs mean opponent team expected goals over previous 6 weeks')