forked from jimmyday12/fitzRoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
176 lines (130 loc) · 6.46 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
options(tibble.print_min = 5, tibble.print_max = 5)
```
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(hexSticker)
library(tidyverse)
sticker(
package = "fitzRoy", # package name to display on sticker
p_size = 8, # size of package name
p_y = 1.5, # y of package name
p_color = "#C9B128", # color of package name
subplot = "man/figures/footy.png", # sticker feature
s_x = 1, # x of feature
s_y = 0.9, # y of feature
s_width = 0.55, # width of feature - maintains aspect ratio
h_size = 2, # border
h_color = "#C9B128", # color of border
h_fill = "white", # color of background
url = "jimmyday12.github.io/fitzRoy", # url at the bottom
u_color = "#C9B128", # color of url at the bottom
u_size = 1.5, # size of url at the bottom
filename = "man/figures/fitz_hex.png" # location to save the image
)
# Get version and dependancy from description
version <- as.vector(read.dcf('DESCRIPTION')[, 'Version']) %>%
gsub('-', '.', .)
dep <- as.vector(read.dcf('DESCRIPTION')[, 'Depends']) %>%
stringr::str_extract("\\d+\\.*\\d+\\.*\\d*")
```
# fitzRoy <img src="man/figures/fitz_hex.png" align="right" width="120" height="139"/>
[![Build Status](https://travis-ci.org/jimmyday12/fitzRoy.svg?branch=master)](https://travis-ci.org/jimmyday12/fitzRoy)
[![Coverage status](https://codecov.io/gh/jimmyday12/FitzRoy/branch/master/graph/badge.svg)](https://codecov.io/github/jimmyday12/FitzRoy?branch=master)
[![packageversion](https://img.shields.io/badge/Package%20version-`r version`-orange.svg?style=flat-square)](commits/master)
[![Project Status](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](/commits/master)
## 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.com and footywire.com. There are also tools for processing and cleaning that data. Future versions will include basic ELO processing functions.
## Installation
You can install fitzRoy from github with:
```{r gh-installation, eval = FALSE, echo = TRUE}
# install.packages("devtools")
devtools::install_github("jimmyday12/fitzRoy")
```
## Usage
The `fitzRoy` package can be used to simply get data from various sources. Some minimal working examples are below.
### 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.
```{r results}
library(fitzRoy)
results <- get_match_results()
tail(results)
```
You can also convert this format into a more analysis friendly "long" format using the helper function `convert_results`.
```{r convert}
results_long <- convert_results(results)
head(results_long)
```
### AFL Tables player results
A new function will return all detailed player stats from afltables.com. Primarily, the easiest way to use this is simply to call `get_afltables_stats` with your required `start_date` and `end_date`.
```{r afltables_match}
#stats <- get_afltables_stats(start_date = "2000-01-01", end_date = "2018-06-01")
#tail(stats)
```
### Fixture
You can access the fixture using `get_fixture` function. This will download the fixture for the current calendar year by default.
```{r fixture}
fixture <- get_fixture()
head(fixture)
```
### 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.
Footywire data from 2010-2017 is included in the package. This will be updated periodically but you will need to update your R package to get access to the latest data.
```{r footywire}
## Show the top of player_stats
head(fitzRoy::player_stats)
```
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.
```{r update_footywire}
## Update footywire data
dat <- update_footywire_stats()
tail(dat)
```
### Weather
We have also included weather data for the 2017 season. This is a work in progress but includes rainfall data from the nearest observation station to each ground. This data is included in the package as `results_weather`.
```{r weather, message=FALSE, warning=FALSE}
library(ggplot2)
library(dplyr)
# Get 2017 weather data
weather <- fitzRoy::results_weather %>%
filter(Season == 2017)
# Plot total rainfal for each home team
ggplot(dat = weather, aes(x = Home.Team, y = Rainfall)) +
geom_col() +
coord_flip()
```
### Squiggle Data
You can access data from the [Squiggle API](api.squiggle.com.au) where the tips of well known AFL tipping models are collected. See full instructions on the above link.
```{r squiggle1, message=FALSE, warning=FALSE}
# You can get the sources
sources <- get_squiggle_data("sources")
head(sources)
```
```{r squiggle2, message=FALSE, warning=FALSE}
# Get all tips
tips <- get_squiggle_data("tips")
head(tips)
```
```{r squiggle3, message=FALSE, warning=FALSE}
# Get` just tips from round 1, 2018
tips <- get_squiggle_data("tips", round = 1, year = 2018)
head(tips)
```
---
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md).
By participating in this project you agree to abide by its terms.