public
Last active

Motion Chart of Premier League Positions by game for past 20+ seasons. Shiny app using googleVis package The data is not currently provided but to-date charts can be viewed at glimmer.rstudio.com/pssguy/eplTableMotion/

  • Download Gist
global.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# load requisite libraries
library(shiny)
library(googleVis)
 
# load raw data (NB not provided)
tableByGame <- read.csv("../tableByGame.csv",stringsAsFactors=FALSE)
 
# to create chart need to repeat one column and get negative of league position as hack
tableByGame$game <- tableByGame$seasonGame
tableByGame$lgPos <- -tableByGame$lgPos
 
# set meaningful column names
colnames(tableByGame) <- c("Team","Season","Res","Pl","Points","GD","GF","Position","Games")
 
# list seasons available for selection
seasonChoice <- unique(tableByGame$Season)
server.R
R
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
shinyServer(function(input, output) {
# use the new renderGvis
output$gvMotion <- renderGvis({
# subset by season
dat <- subset(tableByGame,Season==input$season1)
# set initial conditions
initState <- '
{"iconKeySettings":[{"trailStart":"1901","key":{"dim0":"Man. Utd."}},
{"trailStart":"1901","key":{"dim0":"West Brom"}},{"trailStart":"1901",
"key":{"dim0":"Liverpool"}}],"orderedByX":false,"yZoomedDataMin":-20,
"yZoomedDataMax":-1,"dimensions":{"iconDimensions":["dim0"]},
"showTrails":true,"time":"1901","yLambda":1,"xAxisOption":"2",
"nonSelectedAlpha":0.1,"xZoomedDataMin":1,"yZoomedIn":false,
"playDuration":30000,"xZoomedIn":false,"iconType":"BUBBLE",
"xLambda":1,"colorOption":"_UNIQUE_COLOR","sizeOption":"7",
"duration":{"timeUnit":"Y","multiplier":1},"xZoomedDataMax":27,
"uniColorForNonSelected":false,"yAxisOption":"3","orderedByY":false}'
# produce chart
gvisMotionChart(dat, idvar="Team", timevar="Games",xvar="Pl", yvar="Position", options=list(state=initState))
})
})
ui.R
R
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
shinyUI(pageWithSidebar(
# Application title
headerPanel("EPL Motion Tables"),
# Sidebar with controls to select the relevant team/season/games played
# Options vary with tab selected
sidebarPanel(
helpText("Recreate how any of the EPL seasons unfolded by selecting a year and pressing
the play button. Amend highlighted teams, speed of motion etc. as desired"),
helpText("Based on the wonderful Shiny and googleVis R packages"),
selectInput("season1", label="Select Season:",choices=seasonChoice,selected="2012/2013",multiple=FALSE),
br(),
p("Comprehensive EPL Data - ",
a("PremierSoccerStats", href="http://www.premiersoccerstats.com")
),
p("Regular Articles - ",
a("PSS blog", href="http://premiersoccerstats.com/wordpress/")
),
p("Twitter Feed - ",
a("@pssguy", href="http://twitter.com/pssGuy")
)
),
mainPanel(
tableOutput("gvMotion")
)
))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.