Skip to content

Instantly share code, notes, and snippets.

@antagomir
Created June 19, 2012 11:04
Show Gist options
  • Save antagomir/2953549 to your computer and use it in GitHub Desktop.
Save antagomir/2953549 to your computer and use it in GitHub Desktop.
google motion chart example
# Plot a Motion Chart using googleVis package - a brief example
# Leo Lahti 2012
# Load the library
# Note: requires flash and internet connection
# use install.packages("googleVis") to install the library if needed
library(googleVis)
# Form a motion chart from 'Fruits' example data
# NOTE: the data set ('Fruits' in this example) must be given as data.frame
# which can contain NUMERIC and CHARACTER fields
# (NO FACTORS, NOR LOGICAL variables!).
# The FIRST FOUR FIELDS must be provided in the following order:
# idvar, timevar, two numeric fields, then any number of numeric and character fields
# See help(gvisMotionChart) for details
mchart <- gvisMotionChart(Fruits, "Fruit", "Year")
# Plot the chart (opens in browser, requires flash)
plot(mchart)
# Save as html (needs javascript to open!)
# NOTE: html file viewing does not work locally - store the html file on server and view through internet
print(mchart, file="MotionChart.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment