<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/data-visualization-with-googlevis-exercises-part-1/"></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/04/data-visualization-with-googlevis-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-1"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/06/finger-769300__340.jpg"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-6278" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/06/finger-769300__340-150x150.jpg?resize=150%2C150" data-recalc-dims="1"></a><strong>Line, Bar and Column Charts</strong></p>
<p>Hello everybody! This is the first part of an exciting data visualization series <a target="_blank" rel="nofollow" href="http://www.r-exercises.com/">r exercises.com</a> is going to provide you.</p>
<p>Data visualization involves the creation and study of the visual representation of data. The increasing amounts of data created by Internet activity make the “data visualization” tool totally necessary for data scientists.</p>
<p>One of the best packages that R language provides for this purpose is <strong>googleVis</strong> and guess what, we are going to see its amazing features together. In this first part we are going to see basic stuff of three useful types of charts (<strong>Line Chart</strong>, <strong>Bar Chart</strong> and <strong>Column Chart</strong>) before “digging deeper” in the next parts.</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>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 target="_blank" rel="nofollow" href="http://r-exercises.com/2017/06/04/data-visualization-with-googleVis-solutions-part-1/">here</a>.</p>
<p><strong>Install the Package.</strong></p>
<p><strong>Exercise 1</strong></p>
<p>Install and load the package googleVis.</p>
<p><strong>Create a data frame</strong></p>
<p>First of all let’s create an experimental <code>data.frame</code> to use for all our plots. This is an example:<br>
<code>dfr=data.frame(name=c(&quot;GRE&quot;, &quot;ARG&quot;, &quot;BRA&quot;),<br>
              val1=c(20,32,19),<br>
              val2=c(25,52,12))</code></p>
<p><strong>Exercise 2</strong></p>
<p>Create a data frame named “df”. Give as variables the “Pts” (Points) and “Rbs” (Rebounds) of three NBA players. Names and values are up to you.</p>
<p><strong>Line Chart</strong></p>
<p>To produce a Line Chart you can use:<br>
<code>LineC &lt;- gvisLineChart(df)<br>
plot(LineC)</code></p>
<p><strong>Exercise 3</strong></p>
<p>Create a <code>list</code> named “LineC” and pass to it the “df” data frame you just created as a line chart. <strong>HINT</strong>: Use <code>gvisLineChart()</code>.</p>
<p><strong>Exercise 4</strong></p>
<p>Plot the line chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p><strong>Line chart with two axis</strong></p>
<p>Below there is an example of this type of Line Chart:<br>
<code>LineC2 &lt;- gvisLineChart(df, &quot;name&quot;, c(&quot;val1&quot;,&quot;val2&quot;),<br>
                       options=list(<br>
                         series=&quot;[{targetAxisIndex: 0},<br>
                         {targetAxisIndex:1}]&quot;,<br>
                         vAxes=&quot;[{title:'val1'}, {title:'val2'}]&quot;<br>
                       ))<br>
plot(LineC2)</code></p>
<p>As you can see you create a <code>list</code> (options) that corresponds values 1 &amp; 2 in the two axes respectively.</p>
<p><strong>Exercise 5</strong></p>
<p>Create a single axis Line chart that displays only the “Pts” of the “df” data frame.</p>
<p><strong>Exercise 6</strong></p>
<p>Now create a two axis line chart that displays both “Pts” and “Rbs” of the “df” data frame. <strong>HINT</strong>: Use <code>list()</code>.</p>
<p><strong>Bar Chart</strong></p>
<p>It is quite simple to create a bar chart with googleVis with:<br>
<code>BarC &lt;- gvisBarChart(df)<br>
plot(BarC)</code></p>
<p><strong>Exercise 7</strong></p>
<p>Create a <code>list</code> named “BarC” and pass to it the “df” data frame you just created as a bar chart. <strong>HINT</strong>: Use <code>gvisBarChart()</code>.</p>
<p><strong>Exercise 8</strong></p>
<p>Plot the bar chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<p><strong>Column Chart</strong></p>
<p>Column charts could be considered as vertical bar charts and are quite simple to be created too.<br>
<code>ColumnC &lt;- gvisColumnChart(df)<br>
plot(ColumnC)</code></p>
<p><strong>Exercise 9</strong></p>
<p>Create a <code>list</code> named “ColumnC” and pass to it the “df” data frame you just created as a column chart. <strong>HINT</strong>: Use <code>gvisColumnChart()</code>.</p>
<p><strong>Exercise 10</strong></p>
<p>Plot the column chart. <strong>HINT</strong>: Use <code>plot()</code>.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a title="Getting started with Plotly: basic Plots" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/01/10/getting-started-with-plotly-basic-plots/">Getting started with Plotly: basic Plots </a></li>
<li><a title="Shiny Applications Layouts Exercises (Part-9)" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2017/05/20/shiny-applications-layouts-exercises-part-9/">Shiny Applications Layouts Exercises (Part-9) </a></li>
<li><a title="Customize a scatterplot exercises" target="_blank" rel="nofollow" href="http://www.r-exercises.com/2016/03/17/customize-scatterplot/">Customize a scatterplot exercises </a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/">Explore all our (>1000) R exercises</a></li>
<li><a target="_blank" rel="nofollow" href="http://www.r-exercises.com/r-courses/">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/04/data-visualization-with-googlevis-exercises-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=data-visualization-with-googlevis-exercises-part-1"> 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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...

	<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/F3xNM2N3zzs"></a></div>