<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-3/"></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/20/data-visualization-with-googlevis-exercises-part-3/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-3"> 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>Scatter &amp; Bubble chart</strong></p>
<p>This is the third part of our data visualization series and at this part we will explore the features of two more of the charts that googleVis provides.</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/18/data-visualization-with-googleVis-solutions-part-3/" target="_blank">here</a>.</p>
<p><strong>Package Installation</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><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>Scatter chart</strong></p>
<p>It is quite simple to create a scatter chart with googleVis. We will use the <code>cars</code> dataset. Look at the example below:<br>
<code>ScatterC &lt;- gvisScatterChart(cars)<br>
plot(ScatterC)</code></p>
<p><strong>Exercise 1</strong></p>
<p>Create a list named “ScatterC” and pass to it the <code>cars</code> dataset as a scatter chart. <strong>HINT</strong>: Use <code>gvisScatterChart()</code>.</p>
<p><strong>Exercise 2</strong></p>
<p>Plot the the scatter chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p><strong>Titles</strong></p>
<p>It is time to learn how to enhance the appearance of our googleVis charts. We shall give a title to the chart and also name hAxis and vAxis. Look at the example:<br>
<code>options=list(title=&quot;Cars&quot;, vAxis=&quot;{title:'speed'}&quot;,<br>
                               hAxis=&quot;{title:'dist'}&quot; )</code></p>
<p><strong>Exercise 3</strong></p>
<p>Name your chart “Cars”, your chart’s vAxis “speed”, your chart’s hAxis “dist” and plot the chart. <strong>HINT</strong>: Use <code>list()</code>.</p>
<p><strong>Size</strong></p>
<p>You can adjust the size with <code>width</code> and <code>height</code>.</p>
<p><strong>Exercise 4</strong></p>
<p>Set your chart’s <code>width</code> to 600 and <code>height</code> to 300.</p>
<p><strong>Legend</strong></p>
<p>You can deactivate your chart’s <code>legend</code> if you set it to “none”.</p>
<p><strong>Exercise 5</strong></p>
<p>Deactivate your chart’s <code>legend</code>.</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/06/20/data-visualization-with-googlevis-exercises-part-3/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-3"></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>Point size &amp; Line width</strong></p>
<p>You can determine the size of the chart’s points with <code>pointsize</code> and also choose to unite them with line with <code>linewidth</code>. For example:<br>
<code>pointSize=4,linewidth=3</code></p>
<p><strong>Exercise 6</strong></p>
<p>Set point size to 3 and line width to 2.</p>
<p><strong>Bubble Chart</strong></p>
<p>Another amazing type of chart that googleVis provides is the bubble chart. You can create a simple Bubble Chart of the <code>Fruits</code> dataset like this:<br>
<code>BubbleC &lt;- gvisBubbleChart(Fruits)<br>
plot(BubbleC)</code></p>
<p><strong>Exercise 7</strong></p>
<p>Create a list named “BubbleC” and pass to it the <code>Fruits</code> dataset as a bubble chart. <strong>HINT</strong>: Use <code>gvisBubbleChart()</code>.</p>
<p><strong>Exercise 8</strong></p>
<p>Plot the chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p><strong>Bubble Chart’s Features</strong></p>
<p>As you can see, you created a bubble chart but it seems to be useless. In order to make it useful you should pass to it some of your dataset’s variables as features. It depends on what you want to be displayed and how. If you type <code>head(Fruits)</code> you can easily recognize the numeric variables of your dataset. Then you can use them like this:<br>
<code>BubbleC &lt;- gvisBubbleChart(Fruits,idvar=&quot;VAR1&quot;,<br>
                           xvar=&quot;VAR2&quot;, yvar=&quot;VAR3&quot;,<br>
                           colorvar=&quot;VAR4&quot;, sizevar=&quot;VAR5&quot;)</code></p>
<p><strong>Exercise 9</strong></p>
<p>Find the numeric variables of <code>Fruits</code>, then set “Fruit” as <code>idvar</code>, “Sales” as <code>xvar</code>, “Expenses” as <code>yvar</code>, “Year” as <code>colorvar</code> and “Profit” as <code>sizevar</code> and plot your chart. <strong>HINT</strong>: Use <code>head()</code>.</p>
<p><strong>Data range</strong></p>
<p>You can also adjust the minimum and maximum number of hAxis and vAxis that you want to be displayed. Look at the example below:<br>
<code>options=list(<br>
                            hAxis='{minValue:50, maxValue:150}')</code></p>
<p><strong>Exercise 10</strong></p>
<p>Set your hAxis range from 70 to 130 and your vAxis range from 50 to 100.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<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/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/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/20/data-visualization-with-googlevis-exercises-part-3/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-3"> 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/MzrQ9hpHmW4" height="1"></a></div>