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
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
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
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
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
- so so season
Negative
- conceded more than scored
Positive
\++ recent wins
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.