<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-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/06/11/data-visualization-with-googlevis-exercises-part-2/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-2"> 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>Area, Stepped &amp; Combo charts</strong></p>
<p>In the second part of our series we are going to meet three more googleVis charts. More specifically these charts are <strong>Area Chart</strong>, <strong>Stepped Area Chart</strong> and <strong>Combo</strong> Chart.</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/06/11/data-visualizations-with-googlevis-solutions-part-2/" 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>df=data.frame(name=c(&quot;James&quot;, &quot;Curry&quot;, &quot;Harden&quot;),<br>
              Pts=c(20,23,34),<br>
              Rbs=c(13,7,9))</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.</p>
<p><strong>Area chart</strong></p>
<p>It is quite simple to create an area chart with googleVis with:<br>
<code>AreaC &lt;- gvisBarChart(df)<br>
plot(AreaC)</code></p>
<p><strong>Exercise 1</strong></p>
<p>Create a list named “AreaC” and pass to it the “df” data frame you just created as an area chart. <strong>HINT</strong>: Use <code>gvisAreaChart()</code>.</p>
<p><strong>Exercise 2</strong></p>
<p>Plot the area chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p><strong>Stepped Area chart</strong></p>
<p>Creating a stepped area chart is a little different than the area chart. You have to set the X and Y variables and also make it stacked in order to display the values correctly. Here is an example:<br>
<code>SteppedAreaC &lt;- gvisSteppedAreaChart(df, xvar=&quot;name&quot;,<br>
                                    yvar=c(&quot;val1&quot;, &quot;val2&quot;),<br>
                                    options=list(isStacked=TRUE))<br>
plot(SteppedAreaC)</code></p>
<p><strong>Exercise 3</strong></p>
<p>Create a list named “SteppedAreaC” and pass to it the “df” data frame you just created as a stepped area chart. You should also set the X variable as the players’ names and Y variable as their values. <strong>HINT</strong>: Use <code>gvisSteppedAreaChart()</code>, <code>xvar</code> and <code>yvar</code>.</p>
<p><strong>Exercise 4</strong></p>
<p>Plot the stepped area chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/06/11/data-visualization-with-googlevis-exercises-part-2/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-2"></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 5</strong></p>
<p>Now transform your stepped area chart to stacked to correct it and plot it.</p>
<p><strong>Combo chart</strong></p>
<p>The next chart we are going to meet is the combination of lines and bars chart known as combo chart. You can produce it like this:<br>
<code>ComboC &lt;- gvisComboChart(df, xvar=&quot;country&quot;,<br>
                        yvar=c(&quot;val1&quot;, &quot;val2&quot;),<br>
                        options=list(seriesType=&quot;bars&quot;,<br>
                                     series='{1: {type:&quot;line&quot;}}'))<br>
plot(ComboC)</code></p>
<p><strong>Exercise 6</strong></p>
<p>Create a list named “ComboC” and pass to it the “df” data frame you just created as a combo chart. You should also set the X variable as the players’ names and Y variable as their values. <strong>HINT</strong>: Use <code>gvisComboChart()</code>, <code>xvar</code> and <code>yvar</code>.</p>
<p><strong>Exercise 7</strong></p>
<p>Plot the chart. What kind of chart do you see? <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p>In order to add the bars we have to set it as the example below.<br>
<code>options=list(seriesType=&quot;bars&quot;,<br>
                                     series='{1: {type:&quot;line&quot;}}')</code></p>
<p><strong>Exercise 8</strong></p>
<p>Transform the chart you just created into a combo chart with bars and lines and plot it. <strong>HINT</strong>: Use <code>list()</code>.</p>
<p><strong>Exercise 9</strong></p>
<p>In the previous exercise “Pts” are represented by the bars and “Rbs” by the lines. Try to reverse them.</p>
<p>You can easily transform your combo chart into a column chart or a line chart just be setting <code>series='{1: {type:&quot;line&quot;}}'</code> to 2</p>
<p><strong>Exercise 10</strong></p>
<p>Transform the combo chart into a column chart and then into a line chart.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/06/04/data-visualization-with-googlevis-exercises-part-1/" title="Data Visualization with googleVis exercises part 1" target="_blank">Data Visualization with googleVis exercises part 1 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/01/10/getting-started-with-plotly-basic-plots/" title="Getting started with Plotly: basic Plots" target="_blank">Getting started with Plotly: basic Plots </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/04/30/shiny-application-layouts-exercises-part-3/" title="Shiny Application Layouts exercises part 3" target="_blank">Shiny Application Layouts exercises part 3 </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/06/11/data-visualization-with-googlevis-exercises-part-2/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-2"> 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/wtHy4VXOdzw" height="1"></a></div>