Created
April 13, 2017 02:52
-
-
Save jalapic/77ca484acdf86752700fe1eb86219000 to your computer and use it in GitHub Desktop.
arsenal_over_time
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
### Comparing Arsenal Points per N games over time | |
library(engsoccerdata) | |
library(tidyverse) | |
rollpts <- function(teamname=NULL, N=10){ | |
rbind(england,england_current()) %>% | |
homeaway() %>% | |
filter(team==teamname) %>% | |
mutate(pts = ifelse(gf>ga, 3, ifelse(gf<ga, 0, 1)), | |
rollpts = zoo::rollsum(pts, N, na.pad=T, align=c("right")), | |
gameno = row_number()) %>% | |
ggplot(aes(x=gameno, y=rollpts)) + | |
geom_line() + | |
theme_classic() + | |
ggtitle(teamname, subtitle = paste(N, "game rolling sum of points")) | |
} | |
rollpts("Arsenal", 5) | |
rollpts("Arsenal", 10) | |
rollpts("Arsenal", 20) | |
rbind(england,england_current()) %>% | |
homeaway() %>% | |
filter(team=="Arsenal") %>% | |
mutate(gameno=row_number())->arsenal | |
a1<-lubridate::year(arsenal$Date[1]) | |
a2<-lubridate::year(arsenal$Date[1000]) | |
a3<-lubridate::year(arsenal$Date[2000]) | |
a4<-lubridate::year(arsenal$Date[3000]) | |
a5<-lubridate::year(arsenal$Date[4000]) | |
aw<-which(as.Date(arsenal$Date) > as.Date("1996-09-22"))[[1]] | |
p1=rollpts("Arsenal", 5) + scale_x_continuous(breaks=c(1,1000,2000,3000,4000),labels = c(a1,a2,a3,a4,a5)) + geom_vline(xintercept = aw, color="red", lty=2, lwd=1) | |
p2=rollpts("Arsenal", 10) + scale_x_continuous(breaks=c(1,1000,2000,3000,4000),labels = c(a1,a2,a3,a4,a5)) + geom_vline(xintercept = aw, color="red", lty=2, lwd=1) | |
p3=rollpts("Arsenal", 20) + scale_x_continuous(breaks=c(1,1000,2000,3000,4000),labels = c(a1,a2,a3,a4,a5)) + geom_vline(xintercept = aw, color="red", lty=2, lwd=1) | |
library(gridExtra) | |
grid.arrange(p1,p2,p3,ncol=1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment