Collect data to understand the circumstances of what happened in Chelsea’s Graham Potter era.
Actual analysis will be done on other medium later.
library(rvest)
library(tidyverse)
library(janitor)
library(lubridate)
library(knitr)
Get HTML with rvest.
tmarkt <- read_html("https://www.transfermarkt.com/graham-potter/leistungsdatenDetail/trainer/23954/plus/1?saison_id=&verein_id=631&liga=&wettbewerb_id=&trainer_id=")
tmarkt_df <- tmarkt %>% html_elements(".items") %>% html_table() %>% as.data.frame()
tmarkt_df %>% kable()
| Date | Competition | Season | MD | Home.Team | Home.Team.1 | wappen | Result | wappen.1 | Away.Team | Away.Team.1 | Tactic |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Apr 1, 2023 | Premier League | 22/23 | 29 | Chelsea | NA | 0:2 | NA | Aston Villa | 3-4-3 | NA | NA |
| Mar 18, 2023 | Premier League | 22/23 | 28 | Chelsea | NA | 2:2 | NA | Everton | 3-4-3 | NA | NA |
| Mar 11, 2023 | Premier League | 22/23 | 27 | Leicester | NA | 1:3 | NA | Chelsea | 3-4-3 | NA | NA |
| Mar 7, 2023 | UEFA Champions League | 22/23 | last 16 | Chelsea | NA | 2:0 | NA | Bor. Dortmund | 3-4-3 | NA | NA |
| Mar 4, 2023 | Premier League | 22/23 | 26 | Chelsea | NA | 1:0 | NA | Leeds | 3-4-3 | NA | NA |
| Feb 26, 2023 | Premier League | 22/23 | 25 | Tottenham | NA | 2:0 | NA | Chelsea | 4-2-3-1 | NA | NA |
| Feb 18, 2023 | Premier League | 22/23 | 24 | Chelsea | NA | 0:1 | NA | Southampton | 4-2-3-1 | NA | NA |
| Feb 15, 2023 | UEFA Champions League | 22/23 | last 16 | Bor. Dortmund | NA | 1:0 | NA | Chelsea | 4-2-3-1 | NA | NA |
| Feb 11, 2023 | Premier League | 22/23 | 23 | West Ham | NA | 1:1 | NA | Chelsea | 4-2-3-1 | NA | NA |
| Feb 3, 2023 | Premier League | 22/23 | 22 | Chelsea | NA | 0:0 | NA | Fulham | 4-3-3 Attacking | NA | NA |
| Jan 21, 2023 | Premier League | 22/23 | 21 | Liverpool | NA | 0:0 | NA | Chelsea | 4-1-4-1 | NA | NA |
| Jan 15, 2023 | Premier League | 22/23 | 20 | Chelsea | NA | 1:0 | NA | Crystal Palace | 4-2-3-1 | NA | NA |
| Jan 12, 2023 | Premier League | 22/23 | 7 | Fulham | NA | 2:1 | NA | Chelsea | 3-5-2 flat | NA | NA |
| Jan 8, 2023 | FA Cup | 22/23 | Third Round | Man City | NA | 4:0 | NA | Chelsea | 4-3-3 Attacking | NA | NA |
| Jan 5, 2023 | Premier League | 22/23 | 19 | Chelsea | NA | 0:1 | NA | Man City | 4-2-3-1 | NA | NA |
| Jan 1, 2023 | Premier League | 22/23 | 18 | Nottm Forest | NA | 1:1 | NA | Chelsea | 4-3-3 Attacking | NA | NA |
| Dec 27, 2022 | Premier League | 22/23 | 17 | Chelsea | NA | 2:0 | NA | Bournemouth | 4-3-3 Attacking | NA | NA |
| Nov 12, 2022 | Premier League | 22/23 | 16 | Newcastle | NA | 1:0 | NA | Chelsea | 3-4-2-1 | NA | NA |
| Nov 9, 2022 | EFL Cup | 22/23 | Third Round | Man City | NA | 2:0 | NA | Chelsea | 3-4-3 | NA | NA |
| Nov 6, 2022 | Premier League | 22/23 | 15 | Chelsea | NA | 0:1 | NA | Arsenal | 4-2-3-1 | NA | NA |
| Nov 2, 2022 | UEFA Champions League | 22/23 | Group Stage | Chelsea | NA | 2:1 | NA | Dinamo Zagreb | 4-3-1-2 | NA | NA |
| Oct 29, 2022 | Premier League | 22/23 | 14 | Brighton | NA | 4:1 | NA | Chelsea | 3-4-2-1 | NA | NA |
| Oct 25, 2022 | UEFA Champions League | 22/23 | Group Stage | RB Salzburg | NA | 1:2 | NA | Chelsea | 3-4-1-2 | NA | NA |
| Oct 22, 2022 | Premier League | 22/23 | 13 | Chelsea | NA | 1:1 | NA | Man Utd | 3-4-2-1 | NA | NA |
| Oct 19, 2022 | Premier League | 22/23 | 12 | Brentford | NA | 0:0 | NA | Chelsea | 3-4-2-1 | NA | NA |
| Oct 16, 2022 | Premier League | 22/23 | 11 | Aston Villa | NA | 0:2 | NA | Chelsea | 3-4-2-1 | NA | NA |
| Oct 11, 2022 | UEFA Champions League | 22/23 | Group Stage | AC Milan | NA | 0:2 | NA | Chelsea | 3-5-2 | NA | NA |
| Oct 8, 2022 | Premier League | 22/23 | 10 | Chelsea | NA | 3:0 | NA | Wolves | 4-2-3-1 | NA | NA |
| Oct 5, 2022 | UEFA Champions League | 22/23 | Group Stage | Chelsea | NA | 3:0 | NA | AC Milan | 3-4-2-1 | NA | NA |
| Oct 1, 2022 | Premier League | 22/23 | 9 | Crystal Palace | NA | 1:2 | NA | Chelsea | 4-3-1-2 | NA | NA |
| Sep 14, 2022 | UEFA Champions League | 22/23 | Group Stage | Chelsea | NA | 1:1 | NA | RB Salzburg | 4-2-3-1 | NA | NA |
Drop empty columns.
tmarkt_df <- tmarkt_df %>%
select(-6, -8, -11, -12)
Rename column headers.
tmarkt_df <- tmarkt_df %>%
clean_names() %>%
rename(
score = wappen,
away_team = wappen_1,
tactic = away_team
)
Tidy the table. Add venue identifier where Chelsea played their game.
tmarkt_df <- tmarkt_df %>%
mutate(
venue = case_when(
home_team == "Chelsea" ~ "home",
away_team == "Chelsea" ~ "away"
)
)
Split the score into two columns.
tmarkt_df <- tmarkt_df %>%
separate(score, into = c("home_score", "away_score"), sep = ":")
Add goal_for and goal_against for chelsea.
tmarkt_df <- tmarkt_df %>%
mutate(
goal_for = case_when(
home_team == "Chelsea" ~ home_score,
away_team == "Chelsea" ~ away_score
),
goal_against = case_when(
home_team != "Chelsea" ~ home_score,
away_team != "Chelsea" ~ away_score,
)
)
Convert ‘date’ column to date class.
tmarkt_df$date <- mdy(tmarkt_df$date)
tmarkt_df["date"]
## date
## 1 2023-04-01
## 2 2023-03-18
## 3 2023-03-11
## 4 2023-03-07
## 5 2023-03-04
## 6 2023-02-26
## 7 2023-02-18
## 8 2023-02-15
## 9 2023-02-11
## 10 2023-02-03
## 11 2023-01-21
## 12 2023-01-15
## 13 2023-01-12
## 14 2023-01-08
## 15 2023-01-05
## 16 2023-01-01
## 17 2022-12-27
## 18 2022-11-12
## 19 2022-11-09
## 20 2022-11-06
## 21 2022-11-02
## 22 2022-10-29
## 23 2022-10-25
## 24 2022-10-22
## 25 2022-10-19
## 26 2022-10-16
## 27 2022-10-11
## 28 2022-10-08
## 29 2022-10-05
## 30 2022-10-01
## 31 2022-09-14
tmarkt_df %>% head() %>% kable()
| date | competition | season | md | home_team | home_score | away_score | away_team | tactic | venue | goal_for | goal_against |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2023-04-01 | Premier League | 22/23 | 29 | Chelsea | 0 | 2 | Aston Villa | 3-4-3 | home | 0 | 2 |
| 2023-03-18 | Premier League | 22/23 | 28 | Chelsea | 2 | 2 | Everton | 3-4-3 | home | 2 | 2 |
| 2023-03-11 | Premier League | 22/23 | 27 | Leicester | 1 | 3 | Chelsea | 3-4-3 | away | 3 | 1 |
| 2023-03-07 | UEFA Champions League | 22/23 | last 16 | Chelsea | 2 | 0 | Bor. Dortmund | 3-4-3 | home | 2 | 0 |
| 2023-03-04 | Premier League | 22/23 | 26 | Chelsea | 1 | 0 | Leeds | 3-4-3 | home | 1 | 0 |
| 2023-02-26 | Premier League | 22/23 | 25 | Tottenham | 2 | 0 | Chelsea | 4-2-3-1 | away | 0 | 2 |
Export to csv
tmarkt_df %>%
write.csv(
file = "tmarkt_df"
)