Why might having a one pager be handy.
- You might be really into fantasy sports so want to keep information like points given up by position handy.
Lets say you are playing a mate in your favourite fantasy league, having information like points given up by a team to a position tends to be handy. It’s nothing new, in fact fantasy sports is big in the US and a site like rotowire provides this information for fans quickly.
- You might like constructing your own ladders to like a free kick count ladder.
Maybe you like to debate among your mates, maybe you work for a club and want to know where your team sits every week.
- You might be a punter so having information like Tony presents over in his matterofstats might inform your betting strategy.
No matter the purpose, information is key. But its more than just having the information available. You can construct a lot of the above but it would be very time consuming and probably a bit overwhelming. But that’s why James Day and I have gotten fitzRoy together so all of these things are relatively quick, easy and can be updated weekly.
Fantasy sports has grown in popularity recently and people head over to sites like draftstars and moneyball one of the things people try to do is construct teams for money.
I’m not really into fantasy sports, but the general gist from chatting to people is this.
- You get a salary cap to spend on a team of players
- There are more expensive and less expensive players, but in general price is correlated positively with points
- You pick x players and who ever gets the most fantasy points wins!
If we were to look at the US, one of the more popular websites is rotowire this site people tell me is handy because you are able to see how many points a team gives up to positions.
If you were doing DFS for AFL one of the questions you might come up with, is “I wonder which team gives up the most fantasy points to forwards”.
Well thankfully piecing together a few posts I have done you can do that!
We want to use the fantastic (bit biased here) R package fitzRoy which myself and James Day work on to get the player data from either afltables or footywire. After this we can use my blog post on getting player information where we can pull positions of players roughly (forwards, mids, defence and ruck). Then from there we join them together (there will be some missing data but we can fill that in) and lastly we make a similar table to rotowire which just lists the teams arranged by the average they give up to a certain position.
library(tidyverse)
## ── Attaching packages ─────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.1 ✔ purrr 0.3.2
## ✔ tibble 2.1.1 ✔ dplyr 0.8.0.1
## ✔ tidyr 0.8.3 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(fitzRoy)
df<-fitzRoy::get_footywire_stats(9721:9756)
## Getting data from footywire.com
## Finished getting data
Don’t forget to skim your data.
skimr::skim(df)
## Skim summary statistics
## n obs: 1584
## n variables: 43
##
## ── Variable type:character ─────────────────────────────────────────
## variable missing complete n min max empty n_unique
## Opposition 0 1584 1584 3 16 0 18
## Player 0 1584 1584 8 20 0 474
## Round 0 1584 1584 7 7 0 4
## Status 0 1584 1584 4 4 0 2
## Team 0 1584 1584 3 16 0 18
## Venue 0 1584 1584 3 18 0 9
##
## ── Variable type:Date ──────────────────────────────────────────────
## variable missing complete n min max median n_unique
## Date 0 1584 1584 2019-03-21 2019-04-14 2019-04-02 16
##
## ── Variable type:integer ───────────────────────────────────────────
## variable missing complete n mean sd p0 p25 p50
## AF 0 1584 1584 70.8 26.7 -1 51 69
## B 0 1584 1584 0.4 0.73 0 0 0
## BO 0 1584 1584 0.23 0.6 0 0 0
## CCL 0 1584 1584 0.56 1.09 0 0 0
## CG 0 1584 1584 2.66 1.76 0 1 2
## CL 0 1584 1584 1.72 2.29 0 0 1
## CM 0 1584 1584 0.49 0.86 0 0 0
## CP 0 1584 1584 6.65 3.77 0 4 6
## D 0 1584 1584 16.95 7.34 0 11 16
## ED 0 1584 1584 12.27 5.83 0 8 12
## FA 0 1584 1584 0.91 1.03 0 0 1
## FF 0 1584 1584 0.91 1.04 0 0 1
## G 0 1584 1584 0.53 0.93 0 0 0
## GA 0 1584 1584 0.37 0.65 0 0 0
## GA1 0 1584 1584 0.37 0.65 0 0 0
## HB 0 1584 1584 6.88 4.39 0 4 6
## HO 0 1584 1584 1.7 6.7 0 0 0
## I50 0 1584 1584 2.45 2 0 1 2
## ITC 0 1584 1584 3.31 2.71 0 1 3
## K 0 1584 1584 10.07 4.74 0 6 10
## M 0 1584 1584 4.18 2.57 0 2 4
## Match_id 0 1584 1584 9738.5 10.39 9721 9729.75 9738.5
## MG 0 1584 1584 265.01 143.88 -5 161 241
## MI5 0 1584 1584 0.5 0.9 0 0 0
## One.Percenters 0 1584 1584 2.37 2.48 0 1 2
## R50 0 1584 1584 1.86 2.16 0 0 1
## SC 0 1584 1584 74.97 27.92 0 55 74
## SCL 0 1584 1584 1.16 1.58 0 0 1
## SI 0 1584 1584 4.09 2.54 0 2 4
## T 0 1584 1584 2.71 2.06 0 1 2
## T5 0 1584 1584 0.46 0.8 0 0 0
## TO 0 1584 1584 3.29 2.1 0 2 3
## TOG 0 1584 1584 81.81 10.28 2 78 83
## UP 0 1584 1584 10.06 5.26 0 6 9
## p75 p100 hist
## 88 166 ▁▃▇▇▅▂▁▁
## 1 5 ▇▂▁▁▁▁▁▁
## 0 5 ▇▁▁▁▁▁▁▁
## 1 8 ▇▁▁▁▁▁▁▁
## 4 11 ▆▆▇▂▁▁▁▁
## 3 16 ▇▂▁▁▁▁▁▁
## 1 6 ▇▃▁▁▁▁▁▁
## 8 25 ▅▇▆▂▁▁▁▁
## 21 44 ▁▆▇▇▃▂▁▁
## 16 36 ▂▇▇▆▂▁▁▁
## 1 7 ▇▆▃▁▁▁▁▁
## 1 7 ▇▆▃▁▁▁▁▁
## 1 7 ▇▂▁▁▁▁▁▁
## 1 4 ▇▂▁▁▁▁▁▁
## 1 4 ▇▂▁▁▁▁▁▁
## 9 29 ▅▇▃▂▁▁▁▁
## 0 58 ▇▁▁▁▁▁▁▁
## 4 12 ▇▇▂▂▁▁▁▁
## 5 15 ▇▇▅▃▂▁▁▁
## 13 30 ▂▇▇▆▂▁▁▁
## 6 16 ▇▇▆▃▁▁▁▁
## 9747.25 9756 ▇▆▇▆▆▇▆▇
## 351 901 ▃▇▇▅▂▁▁▁
## 1 7 ▇▂▁▁▁▁▁▁
## 3 17 ▇▂▁▁▁▁▁▁
## 3 15 ▇▃▂▁▁▁▁▁
## 92 177 ▁▃▆▇▅▂▁▁
## 2 11 ▇▂▂▁▁▁▁▁
## 6 16 ▇▇▆▃▁▁▁▁
## 4 14 ▆▇▃▂▁▁▁▁
## 1 5 ▇▂▁▁▁▁▁▁
## 4.25 13 ▃▇▃▃▁▁▁▁
## 88 100 ▁▁▁▁▁▂▇▃
## 13 35 ▃▇▇▃▂▁▁▁
##
## ── Variable type:numeric ───────────────────────────────────────────
## variable missing complete n mean sd p0 p25 p50 p75 p100
## DE 0 1584 1584 72.06 14.12 0 63 72.7 81.8 100
## Season 0 1584 1584 2019 0 2019 2019 2019 2019 2019
## hist
## ▁▁▁▂▅▇▇▃
## ▁▁▁▇▁▁▁▁
Next lets get the players positions and for funsies lets get some other infomation as well.
library(rvest)
## Loading required package: xml2
##
## Attaching package: 'rvest'
## The following object is masked from 'package:purrr':
##
## pluck
## The following object is masked from 'package:readr':
##
## guess_encoding
url<-"https://www.footywire.com/afl/footy/ft_players"
link<-read_html(url)%>%
html_nodes("br+ a , .lnormtop a:nth-child(1)")%>%
html_attr("href")
url_players<-str_c("https://www.footywire.com/afl/footy/",link)
cbind.fill <- function(...){
nm <- list(...)
nm <- lapply(nm, as.matrix)
n <- max(sapply(nm, nrow))
do.call(cbind, lapply(nm, function (x)
rbind(x, matrix(, n-nrow(x), ncol(x)))))
}
player_info <- function(x){
# page <- read_html(x)
page<-read_html(x)
player<- page%>%
html_nodes("#playerProfileName")%>%
html_text()
# player
playing.for<- page%>%
html_nodes("#playerProfileTeamDiv a b")%>%
html_text() %>% as.tibble()
# playing.for
number<- page%>%
html_nodes("#playerProfileTeamDiv > b")%>%
html_text() %>% as.tibble()
# number
weight<-page%>%
html_nodes("#playerProfileData2")%>%
html_text()%>%
str_replace_all("[\r\n]" , "")%>%
str_squish()%>%
str_extract(pattern =("(?<=Weight:).*(?=Position:)"))%>%as.tibble()
# weight
height<-page%>%
html_nodes("#playerProfileData2")%>%
html_text()%>%
str_replace_all("[\r\n]" , "")%>%
str_squish()%>%
str_extract(pattern =("(?<=Height:).*(?=Weight:)"))%>%as.tibble()
# height
draft_position <- page%>%
html_nodes("#playerProfileDraftInfo")%>%
html_text()%>%
str_replace_all("[\r\n]" , "")%>%
str_squish()%>%
str_extract(pattern =("(?<=Drafted: ).*(?=by)"))%>%as.tibble()
# draft_position
club_drafted <- page%>%
html_nodes("#playerProfileDraftInfo a+ a")%>%
html_text()%>%str_replace_all("[\r\n]" , "")%>%
str_squish()%>%
str_remove(".*by") %>% as.tibble()
# club_drafted
position <- page%>%
html_nodes("#playerProfileData2")%>%
html_text()%>%
str_replace_all("[\r\n]" , "")%>%
str_remove(".*Position: ")%>%
str_squish() %>% as.tibble()
sc_price<-page%>%
html_nodes("#playerProfileSupercoach")%>%
html_text()%>%
str_replace_all("[\r\n]" , "")%>%
str_squish()%>%
str_extract(pattern =("(?<=Price:).*(?=Supercoach Profile)"))%>%as.tibble()
# sc_price
af_price<-page%>%
html_nodes("#playerProfileDreamteam")%>%
html_text()%>%
str_replace_all("[\r\n]" , "")%>%
str_squish()%>%
str_extract(pattern =("(?<=Price:).*(?=AFL Fantasy Profile)"))%>%as.tibble()
# af_price
player_information <- cbind.fill(player, playing.for, number, weight, height,draft_position, club_drafted, position, sc_price, af_price)
player_information <- as.tibble(player_information)
#combine, name, and make it a tibble
player_information <- cbind.fill(player, playing.for, number, weight, height,draft_position, club_drafted, position, sc_price, af_price)
player_information <- as.tibble(player_information)
# print(x)
# return(x)
return(player_information)
}
footywire <- purrr::map_df(url_players, player_info)
## Warning: `as.tibble()` is deprecated, use `as_tibble()` (but mind the new semantics).
## This warning is displayed once per session.
names(footywire) <- c("player", "club", "number","weight","height", "draft_position", "club_drafted", "position","sc_price", "af_price")
So now we have our dataframes.
Lets have a looksie
head(footywire)
## # A tibble: 6 x 10
## player club number weight height draft_position club_drafted position
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Jake … Rich… #39 " 76k… " 180… Round 1, Pick… Richmond Ti… Forward
## 2 Ryan … Geel… #45 " 100… " 200… Round 4, Pick… Geelong Cats Ruck
## 3 Gary … Geel… #4 " 87k… " 182… Round 3, Pick… Geelong Cats Midfield
## 4 Blake… St K… #8 " 92k… " 190… Round 1, Pick… St Kilda Sa… Midfiel…
## 5 Marcu… Bris… #24 " 98k… " 192… Round 2, Pick… Western Bul… Defender
## 6 Taylo… Coll… #13 " 83k… " 181… Round 1, Pick… GWS Giants Midfield
## # … with 2 more variables: sc_price <chr>, af_price <chr>
head(df)
## Date Season Round Venue Player Team Opposition Status
## 1 2019-03-21 2019 Round 1 MCG Patrick Cripps Carlton Richmond Home
## 2 2019-03-21 2019 Round 1 MCG Marc Murphy Carlton Richmond Home
## 3 2019-03-21 2019 Round 1 MCG Kade Simpson Carlton Richmond Home
## 4 2019-03-21 2019 Round 1 MCG Dale Thomas Carlton Richmond Home
## 5 2019-03-21 2019 Round 1 MCG Nic Newman Carlton Richmond Home
## 6 2019-03-21 2019 Round 1 MCG Edward Curnow Carlton Richmond Home
## Match_id CP UP ED DE CM GA MI5 One.Percenters BO CCL SCL SI MG TO ITC
## 1 9721 21 11 26 81.2 0 0 0 0 1 4 3 5 263 3 4
## 2 9721 6 23 21 72.4 0 0 0 0 0 0 1 7 530 5 3
## 3 9721 5 19 21 77.8 0 0 0 1 0 1 1 2 462 2 6
## 4 9721 6 17 23 85.2 0 1 0 4 0 0 0 8 434 4 6
## 5 9721 5 17 22 84.6 0 0 0 3 0 0 1 4 584 2 6
## 6 9721 7 18 18 72.0 0 1 2 1 0 0 2 8 303 6 0
## T5 TOG K HB D M G B T HO GA1 I50 CL CG R50 FF FA AF SC
## 1 0 89 10 22 32 1 0 0 6 0 0 2 7 3 2 3 1 101 126
## 2 0 87 16 13 29 4 1 0 1 0 0 5 1 1 4 1 0 97 91
## 3 0 84 15 12 27 6 0 0 1 0 0 1 2 1 5 1 0 92 83
## 4 0 78 15 12 27 3 1 0 2 0 1 3 0 4 5 1 1 90 93
## 5 0 84 21 5 26 9 1 0 2 0 0 2 1 2 12 1 0 115 134
## 6 2 82 13 12 25 12 0 1 3 0 1 3 2 4 1 1 0 113 98
What we can see here is that if we were to attempt to join on team and player name that the team names do not align between the freshly scraped data and the dataset within fitzRoy so lets replace the team names in the freshly scraped footywire data to match those existing already within #fitzRoy.
Too see how its an issue we can use unique
unique(footywire$club)
## [1] "Richmond Tigers" "Geelong Cats"
## [3] "St Kilda Saints" "Brisbane Lions"
## [5] "Collingwood Magpies" "West Coast Eagles"
## [7] "Gold Coast Suns" "North Melbourne Kangaroos"
## [9] "Sydney Swans" "Essendon Bombers"
## [11] "Port Adelaide Power" "Adelaide Crows"
## [13] "Melbourne Demons" "Fremantle Dockers"
## [15] "Hawthorn Hawks" "GWS Giants"
## [17] "Western Bulldogs" "Carlton Blues"
unique(df$Team)
## [1] "Carlton" "Richmond" "Collingwood"
## [4] "Geelong" "Melbourne" "Port Adelaide"
## [7] "Adelaide" "Hawthorn" "Western Bulldogs"
## [10] "Sydney" "Brisbane" "West Coast"
## [13] "St Kilda" "Gold Coast" "GWS"
## [16] "Essendon" "Fremantle" "North Melbourne"
footywire<-footywire%>%
mutate(club=replace(club, club=="Richmond Tigers","Richmond" ))%>%
mutate(club=replace(club, club=="Geelong Cats" ,"Geelong" ))%>%
mutate(club=replace(club, club=="St Kilda Saints" ,"St Kilda" ))%>%
mutate(club=replace(club, club=="Brisbane Lions" ,"Brisbane"))%>%
mutate(club=replace(club, club=="Collingwood Magpies" ,"Collingwood" ))%>%
mutate(club=replace(club, club=="West Coast Eagles" ,"West Coast" ))%>%
mutate(club=replace(club, club=="Gold Coast Suns" ,"Gold Coast" ))%>%
mutate(club=replace(club, club=="North Melbourne Kangaroos","North Melbourne" ))%>%
mutate(club=replace(club, club=="Sydney Swans" , "Sydney" ))%>%
mutate(club=replace(club, club=="Essendon Bombers" ,"Essendon" ))%>%
mutate(club=replace(club, club=="Port Adelaide Power","Port Adelaide" ))%>%
mutate(club=replace(club, club=="Adelaide Crows" ,"Adelaide" ))%>%
mutate(club=replace(club, club=="Melbourne Demons" ,"Melbourne" ))%>%
mutate(club=replace(club, club=="Fremantle Dockers" ,"Fremantle" ))%>%
mutate(club=replace(club, club=="Hawthorn Hawks", "Hawthorn" ))%>%
mutate(club=replace(club, club=="GWS Giants" ,"GWS" ))%>%
mutate(club=replace(club, club== "Footscray" ,"Western Bulldogs" ))%>%
mutate(club=replace(club, club=="Carlton Blues" ,"Carlton" ))
Then we check it. I find using str_sort
helps to see the output on top of each other.
str_sort(unique(footywire$club))
## [1] "Adelaide" "Brisbane" "Carlton"
## [4] "Collingwood" "Essendon" "Fremantle"
## [7] "Geelong" "Gold Coast" "GWS"
## [10] "Hawthorn" "Melbourne" "North Melbourne"
## [13] "Port Adelaide" "Richmond" "St Kilda"
## [16] "Sydney" "West Coast" "Western Bulldogs"
str_sort(unique(df$Team))
## [1] "Adelaide" "Brisbane" "Carlton"
## [4] "Collingwood" "Essendon" "Fremantle"
## [7] "Geelong" "Gold Coast" "GWS"
## [10] "Hawthorn" "Melbourne" "North Melbourne"
## [13] "Port Adelaide" "Richmond" "St Kilda"
## [16] "Sydney" "West Coast" "Western Bulldogs"
From the footywire data, we want to take the player names, club and position and then join this onto the player_stats
dataset from fitzRoy.
footywire_positions<-select(footywire, player, club, position)
footywire_2019<-df
dataset<-left_join(footywire_2019, footywire_positions, by=c("Player"="player", "Team"="club"))
Issue here is that the hyphen names don’t match so we got to change those aswell.
We can view these problem rows as follows.
dataset[rowSums(is.na(dataset)) > 0,]
## Date Season Round Venue Player
## 12 2019-03-21 2019 Round 1 MCG Sam P-Seton
## 97 2019-03-23 2019 Round 1 MCG Alex N-Bullen
## 119 2019-03-23 2019 Round 1 MCG Sam P-Pepper
## 121 2019-03-23 2019 Round 1 MCG Darcy B-Jones
## 297 2019-03-24 2019 Round 1 Marvel Stadium George H-Smith
## 352 2019-03-24 2019 Round 1 Showground Stadium Anthony M-Tipungwuti
## 388 2019-03-24 2019 Round 1 Optus Stadium Luke D-Uniacke
## 396 2019-03-24 2019 Round 1 Optus Stadium Ed V-Willis
## 506 2019-03-30 2019 Round 2 Marvel Stadium Anthony M-Tipungwuti
## 532 2019-03-30 2019 Round 2 Adelaide Oval Darcy B-Jones
## 542 2019-03-30 2019 Round 2 Adelaide Oval Sam P-Pepper
## 555 2019-03-30 2019 Round 2 Adelaide Oval Sam P-Seton
## 609 2019-03-30 2019 Round 2 GMHBA Stadium Alex N-Bullen
## 664 2019-03-31 2019 Round 2 Marvel Stadium Luke D-Uniacke
## 856 2019-04-05 2019 Round 3 MCG Alex N-Bullen
## 871 2019-04-05 2019 Round 3 MCG Anthony M-Tipungwuti
## 887 2019-04-06 2019 Round 3 Marvel Stadium Sam P-Seton
## 992 2019-04-06 2019 Round 3 Gabba Sam P-Pepper
## 998 2019-04-06 2019 Round 3 Gabba Darcy B-Jones
## 1139 2019-04-07 2019 Round 3 MCG Luke D-Uniacke
## 1329 2019-04-13 2019 Round 4 MCG Anthony M-Tipungwuti
## 1373 2019-04-13 2019 Round 4 Adelaide Oval Darcy B-Jones
## 1382 2019-04-13 2019 Round 4 Adelaide Oval Sam P-Pepper
## 1422 2019-04-13 2019 Round 4 Marvel Stadium Luke D-Uniacke
## 1442 2019-04-13 2019 Round 4 Marvel Stadium Cameron E-Yolmen
## 1529 2019-04-14 2019 Round 4 Metricon Stadium Sam P-Seton
## Team Opposition Status Match_id CP UP ED DE CM GA
## 12 Carlton Richmond Home 9721 4 14 11 61.1 0 0
## 97 Melbourne Port Adelaide Home 9723 9 8 9 60.0 0 0
## 119 Port Adelaide Melbourne Away 9723 9 11 10 50.0 1 0
## 121 Port Adelaide Melbourne Away 9723 7 14 14 73.7 1 0
## 297 Gold Coast St Kilda Away 9727 5 12 12 70.6 1 0
## 352 Essendon GWS Away 9728 3 3 3 60.0 0 1
## 388 North Melbourne Fremantle Away 9729 7 8 12 80.0 0 1
## 396 North Melbourne Fremantle Away 9729 0 1 1 100.0 0 0
## 506 Essendon St Kilda Home 9732 2 6 2 28.6 0 0
## 532 Port Adelaide Carlton Home 9733 8 18 15 55.6 0 2
## 542 Port Adelaide Carlton Home 9733 11 11 16 76.2 1 0
## 555 Carlton Port Adelaide Away 9733 10 11 17 81.0 0 0
## 609 Melbourne Geelong Away 9734 6 4 4 44.4 0 0
## 664 North Melbourne Brisbane Home 9736 15 11 21 80.8 0 2
## 856 Melbourne Essendon Home 9740 2 5 5 62.5 0 1
## 871 Essendon Melbourne Away 9740 4 8 12 85.7 0 2
## 887 Carlton Sydney Home 9741 8 10 15 83.3 0 1
## 992 Port Adelaide Brisbane Away 9743 12 19 21 72.4 0 0
## 998 Port Adelaide Brisbane Away 9743 6 11 12 66.7 0 0
## 1139 North Melbourne Hawthorn Away 9746 4 6 8 88.9 0 2
## 1329 Essendon Brisbane Home 9751 8 12 17 85.0 1 0
## 1373 Port Adelaide Richmond Home 9752 3 16 14 77.8 0 1
## 1382 Port Adelaide Richmond Home 9752 11 4 7 53.8 0 0
## 1422 North Melbourne Adelaide Home 9753 5 13 14 82.4 0 0
## 1442 Adelaide North Melbourne Away 9753 9 8 13 86.7 0 0
## 1529 Carlton Gold Coast Away 9755 8 9 14 77.8 0 1
## MI5 One.Percenters BO CCL SCL SI MG TO ITC T5 TOG K HB D M G B T
## 12 0 1 0 1 1 0 282 6 4 0 85 12 6 18 8 0 0 2
## 97 2 1 0 1 1 5 191 3 2 2 89 9 6 15 2 0 2 5
## 119 1 1 1 1 1 10 375 8 2 1 79 12 8 20 3 0 3 2
## 121 0 4 0 0 0 3 212 5 7 0 79 11 8 19 5 0 0 2
## 297 0 2 0 0 0 2 269 5 7 0 78 9 8 17 3 0 0 2
## 352 0 0 1 0 1 1 139 2 1 3 84 3 2 5 1 0 0 5
## 388 3 2 0 1 0 5 129 3 2 2 72 7 8 15 5 1 0 3
## 396 0 1 0 0 0 0 -4 0 0 0 13 0 1 1 0 0 0 0
## 506 0 2 0 1 0 1 129 2 0 5 78 4 3 7 1 0 0 5
## 532 1 3 0 1 2 4 457 4 7 0 88 17 10 27 6 0 1 4
## 542 1 1 1 0 4 4 175 2 4 2 81 7 14 21 3 2 1 8
## 555 0 1 0 1 1 4 332 2 8 0 79 13 8 21 6 1 0 2
## 609 0 2 0 0 4 2 151 3 0 2 90 7 2 9 1 0 0 4
## 664 0 1 0 1 4 8 371 1 3 0 68 11 15 26 5 0 1 3
## 856 0 1 0 0 0 2 34 3 0 1 78 4 4 8 0 1 0 4
## 871 1 1 3 0 0 8 278 1 3 0 88 9 5 14 4 4 0 3
## 887 0 1 0 1 3 6 231 1 3 1 79 10 8 18 4 0 0 5
## 992 0 0 2 5 2 8 699 5 3 1 87 18 11 29 3 0 0 4
## 998 0 2 0 1 1 3 391 5 8 0 86 15 3 18 6 0 0 7
## 1139 0 2 1 0 1 4 192 2 0 0 66 5 4 9 1 0 0 2
## 1329 5 1 2 0 2 12 477 2 0 2 79 16 4 20 10 7 1 3
## 1373 0 1 0 0 0 4 227 3 4 0 82 15 3 18 8 0 0 1
## 1382 0 1 1 0 1 4 188 5 3 0 78 6 7 13 0 1 0 3
## 1422 0 0 2 0 2 5 202 3 0 0 76 10 7 17 4 0 0 2
## 1442 0 4 0 0 2 5 113 3 3 0 78 6 9 15 3 0 0 3
## 1529 0 0 0 2 2 3 91 2 3 0 79 6 12 18 2 0 0 7
## HO GA1 I50 CL CG R50 FF FA AF SC position
## 12 0 0 4 2 2 2 1 0 81 63 <NA>
## 97 0 0 1 2 2 0 1 0 68 67 <NA>
## 119 0 0 3 2 7 1 1 4 61 52 <NA>
## 121 0 0 1 0 4 1 0 1 69 76 <NA>
## 297 0 0 2 0 3 4 2 2 56 65 <NA>
## 352 0 1 5 1 3 0 0 2 30 43 <NA>
## 388 0 1 1 1 2 0 1 0 71 80 <NA>
## 396 0 0 0 0 1 0 0 1 -1 1 <NA>
## 506 0 0 3 1 3 1 1 0 42 28 <NA>
## 532 0 2 7 3 2 1 2 0 108 91 <NA>
## 542 0 0 1 4 2 0 0 2 97 109 <NA>
## 555 0 0 2 2 3 3 0 2 81 108 <NA>
## 609 0 0 5 4 1 0 1 0 45 44 <NA>
## 664 0 2 5 5 1 2 2 1 90 118 <NA>
## 856 0 1 0 0 2 0 1 0 43 40 <NA>
## 871 0 2 3 0 1 0 1 1 83 104 <NA>
## 887 0 1 2 4 1 2 2 0 80 88 <NA>
## 992 0 0 11 7 2 2 3 1 101 115 <NA>
## 998 0 0 4 2 4 1 1 0 98 79 <NA>
## 1139 0 2 3 1 1 0 0 1 31 64 <NA>
## 1329 0 0 5 2 3 0 1 1 139 143 <NA>
## 1373 0 1 1 0 3 1 0 0 79 61 <NA>
## 1382 0 0 1 1 3 0 1 1 48 65 <NA>
## 1422 0 0 3 2 2 0 0 1 61 60 <NA>
## 1442 0 0 2 2 4 0 1 2 52 67 <NA>
## 1529 0 1 1 4 2 0 0 1 73 77 <NA>
So what is the issue?
If we go to say Anthony McDonald-Tipungwuti page where we take his player information we can see that his name is listed as Anthony McDonald-Tipungwuti, however if we were to go to an Essendon Bombers game, such as their one vs the Giants we can see that his name is Anthony M-Tipungwuti which is what is in the fitzRoy dataset.
So lets change the names in the scrape to match the names within fitzRoy.
footywire<-footywire%>%
mutate(player=replace(player, player=="Sam Petrevski-Seton","Sam P-Seton" ))%>%
mutate(player=replace(player, player=="Alex Neal-Bullen","Alex N-Bullen" ))%>%
mutate(player=replace(player, player=="Sam Powell-Pepper","Sam P-Pepper" ))%>%
mutate(player=replace(player, player=="Darcy Byrne-Jones","Darcy B-Jones" ))%>%
mutate(player=replace(player, player=="George Horlin-Smith","George H-Smith" ))%>%
mutate(player=replace(player, player=="Anthony McDonald-Tipungwuti","Anthony M-Tipungwuti" ))%>%
mutate(player=replace(player, player=="Luke Davies-Uniacke","Luke D-Uniacke" ))%>%
mutate(player=replace(player, player=="Cameron Ellis-Yolmen","Cameron E-Yolmen" )) %>%
mutate(player=replace(player, player=="Ed Vickers-Willis","Ed V-Willis" ))
footywire_positions<-select(footywire, player, club, position)
dataset<-left_join(footywire_2019, footywire_positions, by=c("Player"="player", "Team"="club"))
Now lets do some plotting!
Suppose we wanted to see which players did well playing the West Coast Eagles, we could do a simple plot of position by their fantasy scores.
dataset%>%
filter(Opposition=="West Coast")%>%
ggplot(aes(y=AF, x=as.factor(position)))+
geom_point()+
geom_text(aes(label=Player),check_overlap = TRUE, size=2) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
dataset%>%
ggplot(aes(y=AF, x=as.factor(position)))+
geom_violin()+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+ facet_wrap( ~ Opposition, ncol=6)
Ealier on, what we were saying was that we wanted a sheet like you can find on rotowire