-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoccer Possession xG
136 lines (121 loc) · 4.96 KB
/
Soccer Possession xG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
install.packages("worldfootballR")
library(worldfootballR)
library(tidyverse)
library(dplyr)
library(readr)
library(ggplot2)
library(ggrepel)
library(tidyr)
library(ggimage)
help(package = "worldfootballR")
tictoc::tic()
progressr::with_progress({
epl_possession_stats <- worldfootballR::fotmob_get_season_stats(
country = "ENG",
league_name = "Premier League",
season_name = "2023/24",
stat_name = "Possession",
team_or_player = "team"
)
})
tictoc::toc()
possession_stats <- read.csv("C:\\Users\\imksy\\Documents\\PL 202324 possession.csv")
table_pl <- read.csv("C:\\Users\\imksy\\Documents\\PL 202324.csv")
# Merge the datasets based on a common identifier (e.g., team)
combined_table_possession <- merge(table_pl, possession_stats, by = "Squad")
crests <- read_csv("https://raw.githubusercontent.com/dm13450/FootballCrests/main/crest.csv")
combined_table_possession <- left_join(combined_table_possession, crests, by = c("Squad" = "Team"))
# Assuming your dataset is named combined_table_possession
#combined_table_possession$URL[combined_table_possession$Squad == "Sheffield Utd"] <- "https://a.espncdn.com/combiner/i?img=/i/teamlogos/soccer/500/398.png"
avg_poss <- mean(combined_table_possession$Poss, na.rm = TRUE)
avg_xg <- mean(combined_table_possession$xG, na.rm = TRUE)
avg_xga <- mean(combined_table_possession$xGA, na.rm = TRUE)
avg_goals_scored <- mean(combined_table_possession$GF, na.rm = TRUE)
avg_goals_allowed <- mean(combined_table_possession$GA, na.rm = TRUE)
combined_table_possession$Poss <- as.numeric(combined_table_possession$Poss)
combined_table_possession$xG <- as.numeric(combined_table_possession$xG)
combined_table_possession$xGA <- as.numeric(combined_table_possession$xGA)
combined_table_possession$GF <- as.numeric(combined_table_possession$GF)
combined_table_possession$GA <- as.numeric(combined_table_possession$GA)
ggplot(combined_table_possession, aes(x = Poss, y = xG, label = Squad)) +
geom_image(aes(image = URL), size = 0.1) +
geom_vline(xintercept = avg_poss, linetype = "dashed") +
geom_hline(yintercept = avg_xg, linetype = "dashed") +
labs(title = "Possession vs Expected Goals Scored, 2023-24 Premier League",
x = "Possession %",
y = "Expected Goals (xG)",
color = "Team") +
scale_x_continuous(
limits = c(35.0, 65.0),
breaks = c(seq(35.0, 65.0, by = 5.0))
) +
scale_y_continuous(limits = c(38.0, 88.0),
breaks = c(seq(38.0, 88.0, by = 10.0))) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
panel.grid.major = element_line(color = "gray", linetype = "dashed")
)
ggplot(combined_table_possession, aes(x = Poss, y = xGA, label = Squad)) +
geom_image(aes(image = URL), size = 0.1) +
geom_vline(xintercept = avg_poss, linetype = "dashed") +
geom_hline(yintercept = avg_xga, linetype = "dashed") +
labs(title = "Possession vs Expected Goals Allowed, 2023-24 Premier League",
x = "Possession %",
y = "Expected Goals Allowed (xGA)",
color = "Team") +
scale_x_continuous(
limits = c(35.0, 65.0),
breaks = c(seq(35.0, 65.0, by = 5.0))
) +
scale_y_continuous(limits = c(28.0, 78.0),
breaks = c(seq(28.0, 78.0, by = 10.0))) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
panel.grid.major = element_line(color = "gray", linetype = "dashed")
)
ggplot(combined_table_possession, aes(x = xG, y = GF, label = Squad)) +
geom_image(aes(image = URL), size = 0.1) +
geom_vline(xintercept = avg_xg, linetype = "dashed") +
geom_hline(yintercept = avg_goals_scored, linetype = "dashed") +
labs(title = "Expected Goals vs Actual Goals Scored, 2023-24 Premier League",
x = "Expected Goals (xG)",
y = "Actual Goals Scored",
color = "Team") +
scale_x_continuous(
limits = c(38.0, 88.0),
breaks = c(seq(38.0, 88.0, by = 10.0))
) + scale_y_continuous(
limits = c(35, 96),
breaks = c(seq(35, 95, by = 10))
) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
panel.grid.major = element_line(color = "gray", linetype = "dashed")
)
ggplot(combined_table_possession, aes(x = xGA, y = GA, label = Squad)) +
geom_image(aes(image = URL), size = 0.1) +
geom_vline(xintercept = avg_xga, linetype = "dashed") +
geom_hline(yintercept = avg_goals_allowed, linetype = "dashed") +
labs(title = "Expected Goals Allowed vs Actual Goals Allowed, 2023-24 Premier League",
x = "Expected Goals Allowed (xGA)",
y = "Actual Goals Allowed",
color = "Team") +
scale_x_continuous(
limits = c(28.0, 78.0),
breaks = c(seq(28.0, 78.0, by = 10.0))
) + scale_y_continuous(
limits = c(29, 104),
breaks = c(seq(30, 100, by = 10))
) +
#coord_flip() +
scale_x_reverse() +
scale_y_reverse() +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
panel.grid.major = element_line(color = "gray", linetype = "dashed")
)
#https://twitter.com/TotallyREALSpo1/status/1795196682092544162