Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@pssguy /global.R
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
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
# load requisite libraries
# 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)
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",
# produce chart
gvisMotionChart(dat, idvar="Team", timevar="Games",xvar="Pl", yvar="Position", options=list(state=initState))
# Application title
headerPanel("EPL Motion Tables"),
# Sidebar with controls to select the relevant team/season/games played
# Options vary with tab selected
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),
p("Comprehensive EPL Data - ",
a("PremierSoccerStats", href="")
p("Regular Articles - ",
a("PSS blog", href="")
p("Twitter Feed - ",
a("@pssguy", href="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.