1. Introduction

This report is concerned with examining the goals and behinds for each team within the 2023 AFL Season.

2. Data

We will use the fitzRoy package to scrape the 2023 afl season match data. This package contains a lot of functions. We will use fetch_results_afltables to just obtain match results:

library(fitzRoy)
df <- fetch_results_afltables(season = 2023)

The fetch_results_afltables function provides the results for the home team and the away team in separate columns. We can use the code below to get these into the same columns:

df_clean <- 
  df |> 
  
  # filter for regular rounds only
  filter(Round.Type == 'Regular') |> 

  # stack Home.Team and Away.Team on top of each other and rename to just 'Team'
  pivot_longer(cols = c(Home.Team, Away.Team), values_to = 'Team') |> 
  
  # Create new columns for Goals and Behinds based on whether it is home or away team
  mutate(Goals = ifelse(name == 'Home.Team', Home.Goals, Away.Goals),
         Behinds = ifelse(name == 'Home.Team', Home.Behinds, Away.Behinds)) |> 
  
  # Rename Footscray to Western Bulldogs
  mutate(Team = ifelse(Team == 'Footscray', 'Western Bulldogs', Team)) |> 
  
  # Onlt retain variables of interest
  select(Round, Team, Goals, Behinds)

3. Visualisation 1

In the plot below the average number of goals for each game of the 2023 season is visualised as a boxplot for each team. The red dot represents the mean number of goals, and the plot is arranged in descending order.

4. Viusalisation 2

In this plot, the number of goals scored for Adelaide is graphed as a bar chart across each round of the 2023 regular season:

5. Visualisation 3

In this plot, the number of goals and behinds for Adelaide are graphed as a stacked bar chart across each round of the 2023 regular season. This plot is useful for seeing the ratio of goals versus behinds for different matches / rounds