This tutorial analyses North Melbourne players as way of understanding data importation and visuals
What you’ll learn: - How to get team-specific data - Finding top performers
install.packages("fitzRoy")
install.packages("tidyverse")
library(fitzRoy) # For AFL data
library(tidyverse) # For data analysis and graphs
What this does: - fitzRoy gives us AFL statistics - tidyverse for data manipulation and visualization
# Download all 2024 player statistics
north_stats <- fetch_player_stats_afltables(season = 2024)
# Filter for North Melbourne AFL
north_stats <- north_stats %>%
filter(Playing.for == "North Melbourne")
head(north_stats)
## # A tibble: 6 × 81
## Season Round Date Local.start.time Venue Attendance First.name Surname
## <int> <chr> <date> <int> <chr> <int> <chr> <chr>
## 1 2024 2 2024-03-16 1635 Sydney… 8034 Callum Colema…
## 2 2024 2 2024-03-16 1635 Sydney… 8034 Aidan Corr
## 3 2024 2 2024-03-16 1635 Sydney… 8034 Paul Curtis
## 4 2024 2 2024-03-16 1635 Sydney… 8034 Luke Davies…
## 5 2024 2 2024-03-16 1635 Sydney… 8034 Kallan Dawson
## 6 2024 2 2024-03-16 1635 Sydney… 8034 Zane Duursma
## # ℹ 73 more variables: ID <int>, Jumper.No. <chr>, Playing.for <chr>,
## # Kicks <int>, Marks <int>, Handballs <int>, Disposals <int>, Goals <int>,
## # Behinds <int>, Hit.Outs <int>, Tackles <int>, Rebounds <int>,
## # Inside.50s <int>, Clearances <int>, Clangers <int>, Frees.For <int>,
## # Frees.Against <int>, Brownlow.Votes <int>, Contested.Possessions <int>,
## # Uncontested.Possessions <int>, Contested.Marks <int>,
## # Marks.Inside.50 <int>, One.Percenters <int>, Bounces <int>, …
What this does: - Gets all North Melbourne player stats from 2024 season - Each row is one player’s performance in one game
# Calculate total disposals for each player
disposal_leaders <- north_stats %>%
mutate(
Player = paste(First.name, Surname),
Disposals = Kicks + Handballs
) %>%
group_by(Player) %>%
summarise(Total_Disposals = sum(Disposals)) %>%
arrange(desc(Total_Disposals)) %>%
head(10)
# Display top 10
disposal_leaders
## # A tibble: 10 × 2
## Player Total_Disposals
## <chr> <int>
## 1 Luke Davies-Uniacke 638
## 2 Harry Sheezel 626
## 3 Bailey Scott 467
## 4 Tom Powell 462
## 5 Zac Fisher 433
## 6 Tristan Xerri 412
## 7 Darcy Tucker 401
## 8 Colby McKercher 381
## 9 Jy Simpkin 378
## 10 George Wardlaw 344
What this does: - Calculates total disposals (kicks + handballs) - Groups by player and sums their season total - Shows top 10 disposal winners
Type: BAR CHART
ggplot(disposal_leaders, aes(x = reorder(Player, Total_Disposals), y = Total_Disposals)) +
geom_col(fill = "blue") +
coord_flip() +
labs(title = "Top 10 Disposal Winners - North Melbourne 2024",
x = "",
y = "Total Disposals") +
theme_minimal()
What this graph shows: - BAR CHART of North Melbourne’s top ball winners - Shows who gets the most touches
# Calculate total goals for each player
goal_leaders <- north_stats %>%
mutate(Player = paste(First.name, Surname)) %>%
group_by(Player) %>%
summarise(Total_Goals = sum(Goals)) %>%
filter(Total_Goals > 0) %>%
arrange(desc(Total_Goals)) %>%
head(10)
# Display top 10
goal_leaders
## # A tibble: 10 × 2
## Player Total_Goals
## <chr> <int>
## 1 Nick Larkey 46
## 2 Paul Curtis 30
## 3 Cameron Zurhaar 29
## 4 Eddie Ford 15
## 5 Harry Sheezel 14
## 6 Jy Simpkin 11
## 7 Luke Davies-Uniacke 11
## 8 Brynn Teakle 9
## 9 Tom Powell 9
## 10 Zane Duursma 9
What this does: - Sums up total goals for each player - Removes players with zero goals - Shows top 10 goal scorers
Type: BAR CHART
ggplot(goal_leaders, aes(x = reorder(Player, Total_Goals), y = Total_Goals)) +
geom_col(fill = "darkred") +
coord_flip() +
labs(title = "Top 10 Goal Scorers - North Melbourne 2024",
x = "",
y = "Total Goals") +
theme_minimal()
What this graph shows: - BAR CHART of North Melbourne’s leading goal kickers - Shows offensive weapons
# Calculate total kicks for each player
kick_leaders <- north_stats %>%
mutate(Player = paste(First.name, Surname)) %>%
group_by(Player) %>%
summarise(Total_Kicks = sum(Kicks)) %>%
arrange(desc(Total_Kicks)) %>%
head(10)
# Display top 10
kick_leaders
## # A tibble: 10 × 2
## Player Total_Kicks
## <chr> <int>
## 1 Harry Sheezel 330
## 2 Luke Davies-Uniacke 316
## 3 Bailey Scott 313
## 4 Zac Fisher 306
## 5 Colby McKercher 255
## 6 Darcy Tucker 253
## 7 Tom Powell 220
## 8 Jy Simpkin 218
## 9 Luke McDonald 211
## 10 George Wardlaw 203
What this does: - Sums total kicks for each player - Shows who uses the ball by foot most
Type: BAR CHART
ggplot(kick_leaders, aes(x = reorder(Player, Total_Kicks), y = Total_Kicks)) +
geom_col(fill = "purple") +
coord_flip() +
labs(title = "Top 10 Kickers - North Melbourne 2024",
x = "",
y = "Total Kicks") +
theme_minimal()
What this graph shows: - BAR CHART of players who kick the ball most - Important for team ball movement
# Calculate total marks for each player
mark_leaders <- north_stats %>%
mutate(Player = paste(First.name, Surname)) %>%
group_by(Player) %>%
summarise(Total_Marks = sum(Marks)) %>%
arrange(desc(Total_Marks)) %>%
head(10)
# Display top 10
mark_leaders
## # A tibble: 10 × 2
## Player Total_Marks
## <chr> <int>
## 1 Harry Sheezel 133
## 2 Charlie Comben 122
## 3 Bailey Scott 115
## 4 Luke McDonald 105
## 5 Aidan Corr 103
## 6 Darcy Tucker 102
## 7 Nick Larkey 99
## 8 Zac Fisher 90
## 9 Cameron Zurhaar 89
## 10 Tom Powell 86
What this does: - Sums total marks (clean catches) - Shows best aerial players
Type: BAR CHART
ggplot(mark_leaders, aes(x = reorder(Player, Total_Marks), y = Total_Marks)) +
geom_col(fill = "darkgreen") +
coord_flip() +
labs(title = "Top 10 Mark Takers - North Melbourne 2024",
x = "",
y = "Total Marks") +
theme_minimal()
What this graph shows: - BAR CHART of best catchers of the ball - Key forwards and defenders