Description Usage Arguments Value Warnings Note Author(s) References See Also Examples
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.
1 2 3 4 | gvisMotionChart(data, idvar = "id", timevar = "time",
xvar="", yvar="", colorvar="", sizevar="",
date.format = "%Y/%m/%d",
options = list(), chartid)
|
data |
a |
idvar |
column name of |
timevar |
column name of |
xvar |
column name of a numerical vector in |
yvar |
column name of a numerical vector in |
colorvar |
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 |
sizevar |
values in this column are mapped to actual pixel values
using the |
date.format |
if |
options |
list of configuration options for Google Motion Chart.
Further possible components are, taken from https://developers.google.com/chart/interactive/docs/gallery/motionchart:
|
chartid |
character. If missing (default) a random chart id will be generated based on
chart type and |
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, here 'MotionChart' |
|
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
|
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. http://www.myhost.com/myviz.html). See the googleVis package vignette and the Macromedia web site (http://www.macromedia.com/support/documentation/en/flashplayer/help/) for more details.
Please note that a timevar
with values less than 100 will be
shown as years 19xx.
Markus Gesmann markus.gesmann@gmail.com,
Diego de Castillo decastillo@gmail.com
Google Motion Chart API: https://developers.google.com/chart/interactive/docs/gallery/motionchart
Follow the link for Google's data policy.
In 2006 Hans Rosling gave an inspiring talk at TED http://www.ted.com/talks/hans_rosling_shows_the_best_stats_you_ve_ever_seen.html about social and economic developments in the world over the last 50 years, which challenged the views and perceptions of many listeners. Rosling had used extensive data analysis to reach his conclusions. To visualise his talk, he and his team at Gapminder http://www.gapminder.org had developed animated bubble charts, aka motion charts.
In March 2007 Google acquired Trendalyzer from the Gapminder Foundation and the Gapminder team of developers joined Google in California in April 2007.
Yihui Xie, the maintainer of the animation-package
showed in an early blog entry the usage of the Google Motion Chart API
with R:
http://yihui.name/en/2008/11/brownian-motion-using-google-visualization-api-and-r/
Further examples of displaying data with motion charts are available via the Google Public Data Explorer: http://www.google.com/publicdata/home.
Stephen Thompson at Lloyd's developed an Excel version that mimics much of the functionality of the Google motion charts: http://www.lloyds.com/The-Market/Tools-and-Resources/Resources/Statistics-Relating-to-Lloyds/Visualisation
See also print.gvis
, plot.gvis
for
printing and plotting methods, and also the
animation-package
and its function Rosling.bubbles
.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | ## Please note that by default the googleVis plot command
## will open a browser window and requires Flash and Internet
## connection to display the visualisation.
Fruits
## timevar Year
M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
str(M1)
## print.gvis, will concatenate the list into a one long string
M1
plot(M1)
## Combine with another chart, e.g. table
tbl <- gvisTable(Fruits, options=list(height=220))
Mtbl <- gvisMerge(M1, tbl)
plot(Mtbl)
## 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=list(showSidePanel=FALSE))
plot(M4)
## Options: trails un-ticked
M5 <- gvisMotionChart(Fruits, "Fruit", "Year",
options=list(state='{"showTrails":false};'))
plot(M5)
## 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 <-'
{"xZoomedDataMin":1199145600000,"colorOption":"2",
"duration":{"timeUnit":"Y","multiplier":1},"yLambda":1,
"yAxisOption":"4","sizeOption":"_UNISIZE",
"iconKeySettings":[],"xLambda":1,"nonSelectedAlpha":0,
"xZoomedDataMax":1262304000000,"iconType":"LINE",
"dimensions":{"iconDimensions":["dim0"]},
"showTrails":false,"uniColorForNonSelected":false,
"xAxisOption":"_TIME","orderedByX":false,"playDuration":15000,
"xZoomedIn":false,"time":"2010","yZoomedDataMin":0,
"yZoomedIn":false,"orderedByY":false,"yZoomedDataMax":100}
'
M6a <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=myStateSettings))
plot(M6a)
## Newline set explicitly
myStateSettings <-'\n{"iconType":"LINE"}\n'
M6b <- gvisMotionChart(Fruits, "Fruit", "Year", options=list(state=myStateSettings))
plot(M6b)
## 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")
plot(M7)
## For more information see:
## https://developers.google.com/chart/interactive/docs/gallery/motionchart
## See also the demo(WorldBank). It demonstrates how you can access
## country level data from the World Bank to create Gapminder-like
## plots.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.