View source: R/plot_logStrength.R
plot_logStrength | R Documentation |
Visualizes team rankings based on whether the ranking is dynamic or static.
plot_logStrength(x, teams = NULL)
x |
An object of class |
teams |
An optional character vector specifying team names to include in the rankings plot. If |
Dynamic Ranking: Plots Rank Points over Periods for each team with lines and points.
Static Ranking: Plots Rank Points on the x-axis against Team Names on the y-axis with horizontal lines and points.
A ggplot
object:
Dynamic BTD: A lineplot for the log_strengths
over each period, colored by team.
Static BTD: An horizontal barplot for each team.
Roberto Macrì Demartino roberto.macridemartino@deams.units.it.
## Not run:
if (instantiate::stan_cmdstan_exists()) {
library(dplyr)
data("italy")
italy_2020_2021_rank <- italy %>%
select(Season, home, visitor, hgoal, vgoal) %>%
filter(Season == "2020" | Season == "2021") %>%
mutate(match_outcome = case_when(
hgoal > vgoal ~ 1, # Home team wins
hgoal == vgoal ~ 2, # Draw
hgoal < vgoal ~ 3 # Away team wins
)) %>%
mutate(periods = case_when(
row_number() <= 190 ~ 1,
row_number() <= 380 ~ 2,
row_number() <= 570 ~ 3,
TRUE ~ 4
)) %>% # Assign periods based on match number
select(periods,
home_team = home,
away_team = visitor, match_outcome
)
fit_rank_dyn <- btd_foot(
data = italy_2020_2021_rank,
dynamic_rank = TRUE,
rank_measure = "median",
iter_sampling = 1000,
parallel_chains = 2,
chains = 2
)
plot_logStrength(fit_rank_dyn)
plot_logStrength(fit_rank_dyn, teams = c("AC Milan", "AS Roma", "Juventus", "Inter"))
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.