Oleg Mubarakshin
2016-04-09
subtitleFor more details on authoring R presentations please visit https://support.rstudio.com/hc/en-us/articles/200486468.
summary(cars)
speed dist
Min. : 4.0 Min. : 2.00
1st Qu.:12.0 1st Qu.: 26.00
Median :15.0 Median : 36.00
Mean :15.4 Mean : 42.98
3rd Qu.:19.0 3rd Qu.: 56.00
Max. :25.0 Max. :120.00
require(googleVis)
M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Date", date.format = "%Y%m%d")
print(M1, tag="chart")
<!-- MotionChart generated in R 3.2.3 by googleVis 0.5.10 package -->
<!-- Mon Apr 4 18:51:13 2016 -->
<!-- jsHeader -->
<script type="text/javascript">
// jsData
function gvisDataMotionChartID79db303d73b0 () {
var data = new google.visualization.DataTable();
var datajson =
[
[
"Apples",
new Date(2008,11,31),
2008,
"West",
98,
78,
20
],
[
"Apples",
new Date(2009,11,31),
2009,
"West",
111,
79,
32
],
[
"Apples",
new Date(2010,11,31),
2010,
"West",
89,
76,
13
],
[
"Oranges",
new Date(2008,11,31),
2008,
"East",
96,
81,
15
],
[
"Bananas",
new Date(2008,11,31),
2008,
"East",
85,
76,
9
],
[
"Oranges",
new Date(2009,11,31),
2009,
"East",
93,
80,
13
],
[
"Bananas",
new Date(2009,11,31),
2009,
"East",
94,
78,
16
],
[
"Oranges",
new Date(2010,11,31),
2010,
"East",
98,
91,
7
],
[
"Bananas",
new Date(2010,11,31),
2010,
"East",
81,
71,
10
]
];
data.addColumn('string','Fruit');
data.addColumn('date','Date');
data.addColumn('number','Year');
data.addColumn('string','Location');
data.addColumn('number','Sales');
data.addColumn('number','Expenses');
data.addColumn('number','Profit');
data.addRows(datajson);
return(data);
}
// jsDrawChart
function drawChartMotionChartID79db303d73b0() {
var data = gvisDataMotionChartID79db303d73b0();
var options = {};
options["width"] = 600;
options["height"] = 500;
options["state"] = "";
var chart = new google.visualization.MotionChart(
document.getElementById('MotionChartID79db303d73b0')
);
chart.draw(data,options);
}
// jsDisplayChart
(function() {
var pkgs = window.__gvisPackages = window.__gvisPackages || [];
var callbacks = window.__gvisCallbacks = window.__gvisCallbacks || [];
var chartid = "motionchart";
// Manually see if chartid is in pkgs (not all browsers support Array.indexOf)
var i, newPackage = true;
for (i = 0; newPackage && i < pkgs.length; i++) {
if (pkgs[i] === chartid)
newPackage = false;
}
if (newPackage)
pkgs.push(chartid);
// Add the drawChart function to the global list of callbacks
callbacks.push(drawChartMotionChartID79db303d73b0);
})();
function displayChartMotionChartID79db303d73b0() {
var pkgs = window.__gvisPackages = window.__gvisPackages || [];
var callbacks = window.__gvisCallbacks = window.__gvisCallbacks || [];
window.clearTimeout(window.__gvisLoad);
// The timeout is set to 100 because otherwise the container div we are
// targeting might not be part of the document yet
window.__gvisLoad = setTimeout(function() {
var pkgCount = pkgs.length;
google.load("visualization", "1", { packages:pkgs, callback: function() {
if (pkgCount != pkgs.length) {
// Race condition where another setTimeout call snuck in after us; if
// that call added a package, we must not shift its callback
return;
}
while (callbacks.length > 0)
callbacks.shift()();
} });
}, 100);
}
// jsFooter
</script>
<!-- jsChart -->
<script type="text/javascript" src="https://www.google.com/jsapi?callback=displayChartMotionChartID79db303d73b0"></script>
<!-- divChart -->
<div id="MotionChartID79db303d73b0"
style="width: 600; height: 500;">
</div>