<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/data-visualization-with-googlevis-exercises-part-10/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/08/06/data-visualization-with-googlevis-exercises-part-10/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-10"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/06/finger-769300__340.jpg" target="_blank"><img sizes="(max-width: 150px) 100vw, 150px" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/06/finger-769300__340-150x150.jpg?resize=150%2C150" alt="" class="wp-image-6278" data-recalc-dims="1"></a><strong>Timeline, Merging &amp; Flash charts</strong></p>
<p>This is part 10 of our series and we are going to explore the features of some interesting types of charts that googleVis provides like Timeline, Flash and learn how to merge two googleVis charts to one.</p>
<p>Read the examples below to understand the logic of what we are going to do and then test yous skills with the exercise set we prepared for you. Lets begin!</p>
<p>Answers to the exercises are available <a rel="nofollow" href="http://r-exercises.com/2017/08/06/data-visualization-with-googleVis-solutions-part-10/" target="_blank">here</a>.</p>
<p><strong>Package &amp; Data frame</strong></p>
<p>As you already know, the first thing you have to do is install and load the googleVis package with:<br>
<code>install.packages(&quot;googleVis&quot;)<br>
library(googleVis)</code></p>
<p>Secondly we will create an experimental data frame which will be used for our charts’ plotting. You can create it with:<br>
<code>datTLc &lt;- data.frame(Position=c(rep(&quot;President&quot;, 3), rep(&quot;Vice&quot;, 3)),<br>
                    Name=c(&quot;Washington&quot;, &quot;Adams&quot;, &quot;Jefferson&quot;,<br>
                           &quot;Adams&quot;, &quot;Jefferson&quot;, &quot;Burr&quot;),<br>
                    start=as.Date(x=rep(c(&quot;1789-03-29&quot;, &quot;1797-02-03&quot;,<br>
                                          &quot;1801-02-03&quot;),2)),<br>
                    end=as.Date(x=rep(c(&quot;1797-02-03&quot;, &quot;1801-02-03&quot;,<br>
                                        &quot;1809-02-03&quot;),2)))</code></p>
<p>You can explore the “datTLC” data frame with <code>head()</code>. </p>
<p><strong>NOTE</strong>: The charts are created locally by your browser. In case they are not displayed at once press F5 to reload the page. All charts require an Internet connection.</p>
<p><strong>Timeline Chart</strong></p>
<p>It is quite simple to create a timeline chart with googleVis. We will use the “datTLC” data frame we just created.<br>
Look at the example below to create a simple timeline chart:<br>
<code>TLC &lt;- gvisTimeline(data=datTLc)<br>
plot(TLC)</code></p>
<p><strong>Exercise 1</strong></p>
<p>Create a list named “TLC” and pass to it the “datTLC” data frame as a timeline chart. <strong>HINT</strong>: Use <code>gvisTimeline()</code>.</p>
<p><strong>Exercise 2</strong></p>
<p>Plot the the timeline chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p>You can select the variables you want as rows and columns with:<br>
<code>TLC &lt;- gvisTimeline(data=dataframe,<br>
                    rowlabel=&quot;var1&quot;,<br>
                    barlabel=&quot;var2&quot;,<br>
                    start=&quot;var3&quot;,<br>
                    end=&quot;var4&quot;)<br>
plot(TLC)</code></p>
<p><strong>Exercise 3</strong></p>
<p>Put “Name” as <code>rowlabel</code>, “Position” as <code>barlabel</code>, “start” as <code>start</code> “end” as <code>end</code> and plot the chart.</p>
<p><strong>Options</strong></p>
<p>You can group your chart by row or not with:<br>
<code>options=list(timeline=&quot;{groupByRowLabel:true}&quot;)</code></p>
<div>
<aside><img src="http://www.r-exercises.com/2017/08/06/data-visualization-with-googlevis-exercises-part-10/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-10"></aside>
<div><strong>Learn more</strong> about using GoogleVis in the online course <a rel="nofollow" href="http://www.r-exercises.com/product/mastering-in-visualization-with-r-programming/" target="_blank">Mastering in Visualization with R programming</a>. In this course you will learn how to:
<ul>
<li>Work extensively with the GoogleVis package and its functionality</li>
<li>Learn what visualizations exist for your specific use case</li>
<li>And much more</li>
</ul>
</div>
</div>
<p><strong>Exercise 4</strong></p>
<p>Group your timeline chart NOT by <code>rowlabel</code> and plot it.</p>
<p>You can set the colours and size of your chart with:<br>
<code>options=list(timeline=&quot;{groupByRowLabel:false}&quot;,<br>
                                 backgroundColor='yellow',<br>
                                 height=300,<br>
                                 colors=&quot;['blue', 'brown']&quot;))<br>
plot(TLC)</code></p>
<p><strong>Exercise 5</strong></p>
<p>Set the background color of your chart to white, the “Position” colours to red and green respectively, the height to 400 and plot it.</p>
<p><strong>Merging charts</strong></p>
<p>We will now see how to merge two charts to one. For this purpose we are going to use a Geo Chart and a Table which we saw in parts <a rel="nofollow" href="http://www.r-exercises.com/2017/07/11/data-visualization-with-googlevis-exercises-part-6/" target="_blank">6</a> &amp; <a rel="nofollow" href="http://www.r-exercises.com/2017/07/16/data-visualization-with-googlevis-exercises-part-7/" target="_blank">7</a> respectively. </p>
<p><code>Geo &lt;- gvisGeoChart(Exports, &quot;Country&quot;, &quot;Profit&quot;,<br>
                  options=list(width=400, height=400))<br>
Table &lt;- gvisTable(Exports,<br>
               options=list(width=320, height=400))</code></p>
<p>After you create these two charts you can merge them with:<br>
<code>GeoTable &lt;- gvisMerge(Geo,Table, horizontal=TRUE)<br>
plot(GeoTable)</code></p>
<p><strong>Exercise 6</strong></p>
<p>Create a Geo chart and Table like the example above and merge them. <strong>HINT</strong>: Use <code>gvisMerge()</code>.</p>
<p><strong>Flash charts</strong></p>
<p>All the following charts require a <a rel="nofollow" href="https://get.adobe.com/flashplayer/" target="_blank">Flash player</a>.</p>
<p><strong>Motion chart</strong></p>
<p>The most exciting type of chart that googleVis provides, in my opinion, is the motion chart. It is quite simple to create a motion chart with googleVis. We will use the “Fruits” data set for this example. You can see the variables of your data set with <code>head()</code>.<br>
Look at the example below to create a simple motion chart:</p>
<p><code>MotionC=gvisMotionChart(Fruits,<br>
                       idvar = &quot;Fruit&quot;,<br>
                       timevar = &quot;Year&quot;<br>
                       )<br>
plot(MotionC)</code></p>
<p><strong>Exercise 7</strong></p>
<p>Create a list named “MotionC” and pass to it the “Fruits” data set as a motion chart. <strong>HINT</strong>: Use <code>gvisMotionChart()</code>.</p>
<p><strong>Exercise 8</strong></p>
<p>Plot the the motion chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p>As you saw the variables were set automatically, but you can set them as you want with:<br>
<code>MotionC=gvisMotionChart(Fruits,<br>
                       idvar = &quot;Fruit&quot;,<br>
                       timevar = &quot;Year&quot;,<br>
                       xvar = &quot;Expenses&quot;,<br>
                       yvar = &quot;Sales&quot;,<br>
                       sizevar =&quot;Profit&quot;,<br>
                       colorvar = &quot;Location&quot;)<br>
plot(MotionC)</code></p>
<p><strong>Exercise 9</strong></p>
<p>Create a list named “MotionC” and pass to it the “Fruits” data set as a motion chart. You can use the example above or you can use the variables differently to see the differences. <strong>HINT</strong>: Use <code>gvisMotionChart()</code>.</p>
<p><strong>Exercise 10</strong></p>
<p>Plot the the motion chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/06/20/data-visualization-with-googlevis-exercises-part-3/" title="Data Visualization with googleVis exercises part 3" target="_blank">Data Visualization with googleVis exercises part 3 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/06/11/data-visualization-with-googlevis-exercises-part-2/" title="Data Visualization with googleVis exercises part 2" target="_blank">Data Visualization with googleVis exercises part 2 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/06/25/data-visualization-with-googlevis-exercises-part-4/" title="Data Visualization with googleVis exercises part 4" target="_blank">Data Visualization with googleVis exercises part 4 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/08/06/data-visualization-with-googlevis-exercises-part-10/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-10"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/gVDbQObYs8A" height="1"></a></div>