Getting started with AFL Men’s data

Vignette Author

2020-05-23

Overview

The goal of fitzRoy is to provide a set of functions that allows for users to easily get access to AFL data from sources such as AFLtables and Footywire. There are also tools for processing and cleaning that data. Future versions will include basic ELO processing functions.

Load packages

First we need to grab a few packages. If you don’t have any of these, you’ll need to install them.

library(dplyr)
library(elo)
library(lubridate)
library(fitzRoy)

Getting Data

Primarily, the tool can be used to access data from various sources. Data is included in the package and can be access directly however this will not be up to date. Each source of data has functions for updating data during the season.

AFL Tables match results

You can access the basic afl tables match results data. This includes all matches from 1897-current. It is generally updated on the day after a round finishes.

You can access the data directly from the package using match_results. This will be updated periodically but you will need to update your R package to get access to the latest data. It is better to use get_match_results directly, as this will give you up to date results.

You can also convert this format into a more analysis friendly “long” format using the helper function convert_results.

AFL Tables player results

A new function will return all detailed player stats from AFLtables. Primarily, the easiest way to use this is simply to call get_afltables_stats with your required start_date and end_date.

Fixture

You can access the fixture using get_fixture function. This will download the fixture for the current calendar year by default.

Footywire Advanced Player Stats

Footywire data is available in the form of advanced player match statistics from 2010 games onwards. This is when advanced statistics became available.

Note - as of v0.2.0, all internal data has been removed from the package. Please use the relevant functions instead.

The following code no longer works.

We can also use the update_footywire_stats function to get the most up to date data. This will merge data from 2010-current with any new data points.

Alternatively, we can just return one game if we know it’s ID. This can be found by looking at the URL of the match you want. For example, the ID of the 2019 AFL Grand Final is 9927.

https://www.footywire.com/afl/footy/ft_match_statistics?mid=9927

Weather

Note - as of v0.2.0 this has been removed

Squiggle Data

You can access data from the Squiggle API where the tips of well known AFL tipping models are collected. See full instructions on the above link.

Create Ladder

You can recreate the ladder for every round of the home and away season since 1897. You can either pass in a dataframe extracted using get_match_results (ideal as get_match_results doesn’t need to be executed every time return_ladder is called):

Or leave the match_results_df argument blank (which will execute the get_match_results() function internally):

Alternatively, we can also return the ladder for any round, or any season, or a combination of both round and season: