googleVis (version 0.6.0)

gvisMotionChart: Google Motion Chart with R motionchart



The gvisMotionChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser in Flash. A motion chart is a dynamic chart to explore several indicators over time.


gvisMotionChart(data, idvar = "id", timevar = "time", xvar = "", yvar = "", colorvar = "", sizevar = "", date.format = "%Y/%m/%d", options = list(), chartid)


a data.frame. The data has to have at least four columns with subject name (idvar), time (timevar) and two columns of numeric values. Further columns, numeric and character/factor are optional. The combination of idvar and timevar has to describe a unique row. The column names of the idvar and timevar have to be specified. Further columns, if not specified by the other arguments (xvar, yvar, colorvar, sizevar), will be assumed to be in the order of the arguments.
column name of data with the subject to be analysed.
column name of data which shows the time dimension. The information has to be either numeric, of class Date or a character which follows the pattern 'YYYYWww' (e.g. '2010W04' for weekly data) or 'YYYYQq' (e.g. '2010Q1' for quarterly data).
column name of a numerical vector in data to be plotted on the x-axis.
column name of a numerical vector in data to be plotted on the y-axis.
column name of data that identifies bubbles in the same series. Use the same value to identify all bubbles that belong to the same series; bubbles in the same series will be assigned the same color. Series can be configured using the series option.
values in this column are mapped to actual pixel values using the sizeAxis option.
if timevar is of class Date then this argument specifies how the dates are reformatted to be used by JavaScript.
list of configuration options for Google Motion Chart. The options are documented in detail by Google online:

The parameters can be set via a named list. The parameters have to map those of the Google documentation.

  • Boolean arguments are set to either TRUE or FALSE, using the R syntax.

  • Google API parameters with a single value and with names that don't include a "." are set like one would do in R, that is options=list(width=200, height=300). Exceptions to this rule are the width and height options for gvisAnnotatedTimeLine and gvisAnnotationChart. For those two functions, width and height must be character strings of the format "Xpx", where X is a number, or "automatic". For example, options=list(width="200px", height="300px").
  • Google API parameters with names that don't include a ".", but require multivalues are set as a character, wrapped in "[ ]" and separated by commas, e.g.
  • options=list(colors="['#cbb69d', '#603913', '#c69c6e']")

  • Google API parameters with names that do include a "." present parameters with several sub-options and have to be set as a character wrapped in " ". The values of those sub-options are set via parameter:value. Boolean values have to be stated as 'true' or 'false'. For example the Google documentaion states the formating options for the vertical axis and states the parameter as vAxis.format. Then this paramter can be set in R as:
  • options=list(vAxis="{format:'#,###%'}").

  • If several sub-options have to be set, e.g.
  • titleTextStyle.color, titleTextStyle.fontName and titleTextStyle.fontSize, then those can be combined in one list item such as:

    options=list(titleTextStyle="{color:'red', fontName:'Courier', fontSize:16}")

  • paramters that can have more than one value per sub-options are wrapped in "[ ]". For example to set the labels for left and right axes use:
  • options=list(vAxes="[{title:'val1'}, {title:'val2'}]")

  • gvis.editor a character label for an on-page button that opens an in-page dialog box enabling users to edit, change and customise the chart. By default no value is given and therefore no button is displayed.
  • For more details see the Google API documentation and the R examples below.

    character. If missing (default) a random chart id will be generated based on chart type and tempfile


    gvisMotionChart returns list of class "gvis" and "list". An object of class "gvis" is a list containing at least the following components:
    Google visualisation type
    character id of the chart object. Unique chart ids are required to place several charts on the same page.
    a list with the building blocks for a page
    a character string of a html page header: ...,
    a named character vector of the chart's building blocks:
    Opening .
    Call of the jsDisplayChart function.
    container to embed the chart into the page.
    character string of a standard caption, including data name and chart id.
    character string of a html page footer: ..., including the used R and googleVis version and link to Google's Terms of Use.


    Because of Flash security settings the chart might not work correctly when accessed from a file location in the browser (e.g., file:///c:/webhost/myhost/myviz.html) rather than from a web server URL (e.g. See the googleVis package vignette and the Macromedia web site ( for more details.


    Please note that a timevar with values less than 100 will be shown as years 19xx.


    Google Chart Tools API:

    See Also

    See also print.gvis, plot.gvis for printing and plotting methods.


    Run this code
    ## Please note that by default the googleVis plot command
    ## will open a browser window and requires Flash and Internet
    ## connection to display the visualisation.
    M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
    ## Not run: 
    # ## Usage of date variable
    # M2 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Date",
    #                       date.format = "\%Y\%m\%d") 
    #                       plot(M2)
    # ## Display weekly data:
    # M3 <- gvisMotionChart(Fruits, "Fruit", "Date", date.format="\%YW\%W")
    # plot(M3) 
    # ## End(Not run)
    ## Options: no side panel on the right
    M4 <- gvisMotionChart(Fruits,"Fruit", "Year",
    ## Options: trails un-ticked
    M5 <- gvisMotionChart(Fruits, "Fruit", "Year",
    ## You can change some of displaying settings via the browser,
    ## e.g. the level of opacity of non-selected items, or the chart type.
    ## The state string from the 'Advanced' tab can be used to set those
    ## settings via R. Just copy and past the string from the browser into
    ## the argument state of the options list.
    ## Here is an example of a motion chart, with an initial line chart
    ## displayed. Ensure that you have a newline at the start and end of
    ## your settings string.
    myStateSettings <-'
    M6a <- gvisMotionChart(Fruits, "Fruit", "Year", 
    ## Newline set explicitly
    myStateSettings <-'\n{"iconType":"LINE"}\n'
    M6b <- gvisMotionChart(Fruits, "Fruit", "Year", 
    ## Define which columns are used for the initial setup of the various
    ## dimensions
    M7 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year",
                          xvar="Profit", yvar="Expenses",
                          colorvar="Location", sizevar="Sales")
    ## For more information see:
    ## See also the demo(WorldBank). It demonstrates how you can access
    ## country level data from the World Bank to create Gapminder-like
    ## plots.

    Run the code above in your browser using DataLab