To rebuild run make build
.
library(glue)
library(kableExtra)
library(tidyverse)
library(FootballData)
select_country <- "England"
select_league <- "Championship"
select_team_interest <- "Nottingham Forest FC"
Get all competitions.
competitions <- football_get_competition()
glimpse(competitions)
## Rows: 152
## Columns: 6
## $ league <chr> "WC Qualification", "Primera B Nacional", "Superliga A…
## $ competition_id <int> 2006, 2023, 2024, 2149, 2025, 2147, 2008, 2026, 2020, …
## $ plan <chr> "TIER_FOUR", "TIER_FOUR", "TIER_TWO", "TIER_FOUR", "TI…
## $ country <chr> "Africa", "Argentina", "Argentina", "Argentina", "Arge…
## $ url_flag <chr> NA, NA, NA, NA, NA, NA, NA, NA, "https://upload.wikime…
## $ flag <glue> NA, NA, NA, NA, NA, NA, NA, NA, "<img src='https://up…
Filter to the ones on the free plan.
competitions_curated <- competitions %>%
filter(
plan == "TIER_ONE"
)
Show them.
competitions_curated %>%
select(country,league,flag) %>%
knitr::kable(escape = F)
country |
league |
flag |
---|---|---|
Brazil |
Série A |
NA |
England |
Championship |
|
England |
Premier League |
|
Europe |
UEFA Champions League |
NA |
Europe |
European Championship |
NA |
France |
Ligue 1 |
|
Germany |
Bundesliga |
|
Italy |
Serie A |
|
Netherlands |
Eredivisie |
|
Portugal |
Primeira Liga |
|
Spain |
Primera Division |
|
World |
FIFA World Cup |
NA |
Look at England - Championship.
league <- competitions_curated %>%
filter(country == select_country & league == select_league) %>%
pull(competition_id) %>%
as.character() %>%
football_get_teams()
league %>%
select(team,crest) %>%
knitr::kable(escape = F)
team |
crest |
---|---|
Blackburn Rovers FC |
|
Norwich City FC |
|
Queens Park Rangers FC |
|
Stoke City FC |
|
Swansea City AFC |
|
Birmingham City FC |
|
Derby County FC |
|
Middlesbrough FC |
|
Sheffield Wednesday FC |
|
Watford FC |
|
Nottingham Forest FC |
|
Reading FC |
|
Barnsley FC |
|
Millwall FC |
|
Rotherham United FC |
|
Bristol City FC |
|
Luton Town FC |
|
Huddersfield Town AFC |
|
Brentford FC |
|
Cardiff City FC |
|
AFC Bournemouth |
|
Coventry City FC |
|
Preston North End FC |
|
Wycombe Wanderers FC |
What’s the current league standings.
standings <- competitions_curated %>%
filter(country == select_country & league == select_league) %>%
pull(competition_id) %>%
as.character() %>%
football_get_standing()
glimpse(standings)
## Rows: 24
## Columns: 14
## $ position <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,…
## $ playedGames <int> 28, 27, 27, 27, 28, 28, 28, 27, 28, 28, 28, 27, 28, 27…
## $ form <chr> "L,D,D,W,W", "W,W,W,D,W", "W,W,D,W,W", "D,W,D,W,W", "D…
## $ won <int> 16, 15, 15, 14, 13, 12, 11, 11, 9, 12, 11, 10, 7, 9, 9…
## $ draw <int> 7, 9, 8, 6, 9, 9, 7, 6, 12, 3, 3, 6, 14, 7, 7, 9, 6, 8…
## $ lost <int> 5, 3, 4, 7, 6, 7, 10, 10, 7, 13, 14, 11, 7, 11, 11, 10…
## $ points <int> 55, 54, 53, 48, 48, 45, 40, 39, 39, 39, 36, 36, 35, 34…
## $ goalsFor <int> 35, 52, 35, 40, 31, 43, 31, 41, 32, 29, 32, 29, 26, 35…
## $ goalsAgainst <int> 23, 27, 15, 29, 20, 28, 28, 29, 29, 33, 36, 34, 26, 31…
## $ goalDifference <int> 12, 25, 20, 11, 11, 15, 3, 12, 3, -4, -4, -5, 0, 4, -7…
## $ team_id <int> 68, 402, 72, 355, 346, 1044, 343, 59, 70, 387, 1081, 3…
## $ team <chr> "Norwich City FC", "Brentford FC", "Swansea City AFC",…
## $ url_team <chr> "https://upload.wikimedia.org/wikipedia/en/8/8c/Norwic…
## $ crest <glue> "<img src='https://upload.wikimedia.org/wikipedia/en/…
standings %>%
select(position,points,team,form,crest) %>%
knitr::kable(escape = F)
position |
points |
team |
form |
crest |
---|---|---|---|---|
1 |
55 |
Norwich City FC |
L,D,D,W,W |
|
2 |
54 |
Brentford FC |
W,W,W,D,W |
|
3 |
53 |
Swansea City AFC |
W,W,D,W,W |
|
4 |
48 |
Reading FC |
D,W,D,W,W |
|
5 |
48 |
Watford FC |
D,L,D,W,W |
|
6 |
45 |
AFC Bournemouth |
W,L,L,L,L |
|
7 |
40 |
Middlesbrough FC |
L,D,L,L,W |
|
8 |
39 |
Blackburn Rovers FC |
L,W,W,D,W |
|
9 |
39 |
Stoke City FC |
D,D,L,D,D |
|
10 |
39 |
Bristol City FC |
L,L,L,W,L |
|
11 |
36 |
Preston North End FC |
L,L,D,W,L |
|
12 |
36 |
Barnsley FC |
D,D,L,L,L |
|
13 |
35 |
Millwall FC |
W,D,D,D,W |
|
14 |
34 |
Cardiff City FC |
W,D,D,L,L |
|
15 |
34 |
Luton Town FC |
D,L,L,W,L |
|
16 |
33 |
Queens Park Rangers FC |
W,W,L,W,W |
|
17 |
33 |
Huddersfield Town AFC |
D,D,L,L,L |
|
18 |
32 |
Nottingham Forest FC |
W,W,D,L,W |
|
19 |
31 |
Coventry City FC |
D,L,D,W,L |
|
20 |
29 |
Rotherham United FC |
W,W,L,W,D |
|
21 |
28 |
Derby County FC |
L,W,W,W,L |
|
22 |
28 |
Birmingham City FC |
L,D,D,L,W |
|
23 |
19 |
Sheffield Wednesday FC |
L,W,W,L,W |
|
24 |
16 |
Wycombe Wanderers FC |
L,D,L,L,W |
upcoming_foe_data <- standings %>%
filter(
team == select_team_interest
) %>%
pull(team_id) %>%
as.character() %>%
football_get_upcoming() %>%
arrange(utcDate)
glimpse(upcoming_foe_data)
## Rows: 18
## Columns: 14
## $ id <int> 306708, 306723, 306732, 306745, 306756, 306765, 306785, 3…
## $ competition <df[,3]> <data.frame[18 x 3]>
## $ season <df[,5]> <data.frame[18 x 5]>
## $ utcDate <chr> "2021-02-13T12:30:00Z", "2021-02-17T19:00:00Z", "2021-02-…
## $ status <chr> "SCHEDULED", "SCHEDULED", "SCHEDULED", "SCHEDULED", "SCHE…
## $ matchday <int> 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 4…
## $ stage <chr> "REGULAR_SEASON", "REGULAR_SEASON", "REGULAR_SEASON", "RE…
## $ group <chr> "Regular Season", "Regular Season", "Regular Season", "Re…
## $ lastUpdated <chr> "2021-01-22T19:33:55Z", "2021-01-26T23:33:52Z", "2020-08-…
## $ odds <df[,1]> <data.frame[18 x 1]>
## $ score <df[,6]> <data.frame[18 x 6]>
## $ homeTeam <df[,2]> <data.frame[18 x 2]>
## $ awayTeam <df[,2]> <data.frame[18 x 2]>
## $ referees <list> [[], [], [], [], [], [], [], [], [], [], [], [], [], [],…
metrics <- football_calculate_competition_metrics(standings)
# table
metrics %>%
mutate(Team = paste(crest,team)) %>%
select(Team, Mood = metric_mood) %>%
mutate(
Mood = as.character(Mood),
Mood = case_when(
str_detect(Mood,"Jubilant") ~ cell_spec(
Mood, color = "black", background = "#98FB98"
),
str_detect(Mood,"Optimistic") ~ cell_spec(
Mood, color = "black", background = "#e5f5f9"
),
str_detect(Mood,"Ambivalent") ~ cell_spec(
Mood, color = "black", background = "#f7fcb9"
),
str_detect(Mood,"Doldrums") ~ cell_spec(
Mood, color = "black", background = "#ffc4c4"
),
TRUE ~ Mood
)
) %>%
knitr::kable(escape = F)
Team |
Mood |
---|---|
Norwich City FC |
Jubilant: Norwich City FC are on a roll |
Brentford FC |
Jubilant: Brentford FC are on a roll |
Swansea City AFC |
Jubilant: Swansea City AFC are on a roll |
Reading FC |
Optimistic: Reading FC are doing well |
Watford FC |
Optimistic: Watford FC are doing well |
AFC Bournemouth |
Optimistic: AFC Bournemouth are doing well |
Middlesbrough FC |
Optimistic: Middlesbrough FC are doing well |
Blackburn Rovers FC |
Optimistic: Blackburn Rovers FC are doing well |
Stoke City FC |
Ambivalent: Stoke City FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Bristol City FC |
Ambivalent: Bristol City FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Preston North End FC |
Ambivalent: Preston North End FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Barnsley FC |
Ambivalent: Barnsley FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Millwall FC |
Ambivalent: Millwall FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Cardiff City FC |
Ambivalent: Cardiff City FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Luton Town FC |
Ambivalent: Luton Town FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Queens Park Rangers FC |
Ambivalent: Queens Park Rangers FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Huddersfield Town AFC |
Ambivalent: Huddersfield Town AFC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Nottingham Forest FC |
Ambivalent: Nottingham Forest FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Coventry City FC |
Ambivalent: Coventry City FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Rotherham United FC |
Ambivalent: Rotherham United FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Derby County FC |
Ambivalent: Derby County FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Birmingham City FC |
Ambivalent: Birmingham City FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Sheffield Wednesday FC |
Ambivalent: Sheffield Wednesday FC aren’t doing well, but hey - at least they aren’t Wycombe Wanderers FC |
Wycombe Wanderers FC |
Doldrums: Wycombe Wanderers FC are doing poorly. Avoid supporters at all costs. |
metrics_team <- metrics %>%
filter(team == select_team_interest)
metrics_team_summary <- metrics_team %>% select(team,crest,metric_mood)
metrics_team %>%
select(-c(metric_mood_numeric,metric_mood)) %>%
pivot_longer(starts_with("metric"),
names_to = "Variable",
values_to = "Modifier"
) %>%
mutate(
Effect = case_when(
str_detect(Modifier, "\\+") ~ "Positive",
str_detect(Modifier, "\\-") ~ "Negative",
TRUE ~ "Neutral"
)
) %>%
select(
Effect,Modifier
) %>% arrange(Effect) %>%
mutate(
Effect = case_when(
Effect == "Negative" ~ cell_spec(
Effect, color = "white", bold = TRUE, background = "#F66E5CFF"
),
Effect == "Positive" ~ cell_spec(
Effect, color = "white", bold = TRUE, background = "#228B22"
),
TRUE ~ Effect
)
) %>%
knitr::kable(escape = F)
Effect |
Modifier |
---|---|
Negative |
|
Negative |
|
Positive | ++ recent wins |