This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Data on set piece goals scored and conceded in 2016-17 from [here](https://objective-football.blogspot.co.uk/2016/08/201617-open-playset-piecepenalty-data.html). | |
--- | |
# Get data | |
```{r} | |
library(dplyr) | |
library(XML) | |
library(RCurl) | |
library(engsoccerdata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(dplyr) | |
require(ggplot2) | |
# get week-by-week data for current season and last (data originally taken from official API) | |
d17 <- read.csv(url("https://github.com/JoGall/FantasyPL/blob/master/17-18.csv")) | |
d16 <- read.csv(url("https://github.com/JoGall/FantasyPL/blob/master/16-17_formatted.csv")) | |
# compute price changes | |
ss16 <- d16 %>% | |
group_by(player_id) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dataframe 'dat' w/ x,y-coords in columns 'x' and 'y' and timestamp in column, 'ts', e.g.: | |
library(soccermatics) | |
attach(tromso) | |
dat <- subset(tromso, id == 8)[,c(1,3:4)] | |
#calculate direction of each vector angle (in radians) | |
v <- diff(complex(real = dat$x, imaginary = dat$y)) | |
dat$direction <- c(NA, diff(Arg(v)) %% (2*pi), NA) - pi | |
# calculate speed (distance / time interval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
library(scales) | |
# SAMPLE DATA | |
set.seed(123) | |
# get all dates in a range | |
start_date <- as.Date("2017-01-01") | |
end_date <- as.Date("2017-06-01") | |
dates <- seq(start_date, end_date, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggforce) # gives us `geom_circle` and `geom_arc` functions | |
# pitch dimensions | |
courtLength <- 30.5 | |
courtWidth <- 15.25 | |
courtRunoff <- 3.05 | |
# aesthetic parameters | |
pitch_col <- "grey90" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Computes number of neighbours in common between first degree neighbourhood of each vertex in an igraph network | |
# Not sure if this is meaningful metric yet but seems like it could be interesting! | |
# FUNCTION -------------------------------------------------------------------- | |
common.neighbours <- function(graph) { | |
lapply(unique(V(graph)), function(v) { | |
# get vertices of 1st-order neighbourhood for focal vertex (and omit self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(soccermatics) | |
library(StatsBombR) | |
# get data from StatsBomb | |
fixture <- FreeMatches(37) %>% | |
filter(home_team.home_team_name == "Reading WFC" & away_team.away_team_name == "Yeovil Town LFC") | |
# helper function from my fork of statsbombr package: https://github.com/JoGall/StatsBombR | |
# or code here: https://github.com/JoGall/StatsBombR/blob/master/R/allinfo.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#devtools::install_github("statsbomb/StatsBombR") #install package | |
#devtools::install_github("jogall/StatsBombR") #or fork for R v<5.0 if necessary | |
library(StatsBombR) | |
# see all free competitions | |
FreeCompetitions() | |
# e.g. get all fixtures from FIFA World Cup | |
fixtures <- FreeMatches(43) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compute total minutes played per player ------------------------------- | |
statsbombMinsPlayed <- function(dat) { | |
dat <- dat %>% | |
group_by(match_id) %>% | |
mutate(end = max(ElapsedTime)) | |
# starting XI | |
minutes <- dat %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
player_id | age | elo | prop_mins_played | |
---|---|---|---|---|
1 | 18 | 60 | 0.330277778 | |
1 | 19 | 60 | 0.620325203 | |
1 | 20 | 60 | 0.791725768 | |
1 | 21 | 60 | 0.791472868 | |
1 | 22 | 60 | 0.868888889 | |
1 | 23 | 70 | 0.631860776 | |
1 | 24 | 70 | 0.850793651 | |
1 | 25 | 70 | 0.5 | |
1 | 25 | 80 | 0.627664399 |
OlderNewer