plot_logStrength: Plot Rankings for btdFoot Objects

View source: R/plot_logStrength.R

plot_logStrengthR Documentation

Plot Rankings for btdFoot Objects

Description

Visualizes team rankings based on whether the ranking is dynamic or static.

Usage

plot_logStrength(x, teams = NULL)

Arguments

x

An object of class btdFoot.

teams

An optional character vector specifying team names to include in the rankings plot. If NULL, all teams are included.

Details

  • 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.

Value

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.

Author(s)

Roberto Macrì Demartino roberto.macridemartino@deams.units.it.

Examples

## 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)


LeoEgidi/footBayes documentation built on June 2, 2025, 11:32 a.m.