Data Visualization with googleVis exercises part 5

June 30, 2017
By

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

Candlestick, Pie, Gauge, Intensity Charts

In the fifth part of our journey we will meet some special but more and more usable types of charts that googleVis provides. More specifically you will learn about the features of Candlestick, Pie, Gauge and Intensity Charts.

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!

Answers to the exercises are available here.

Package & Data frame

As you already know, the first thing you have to do is install and load the googleVis package with:
install.packages("googleVis")
library(googleVis)

Secondly we will create an experimental data frame which will be used for our charts’ plotting. You can create it with:
co=data.frame(country=c("US", "GB", "BR"),
population=c(15,17,19),
size=c(33,42,22))

NOTE: The charts are created locally by your browser. In case they are not displayed at once press F5 to reload the page.

Candlestick chart

It is quite simple to create a Candlestick Chart with googleVis. We will use the “OpenClose” dataset. Look at the example below:
CandleC <- gvisCandlestickChart(OpenClose,
options=list(legend='none'))
plot(CandleC)

Exercise 1

Create a list named “CandleC” and pass to it the “OpenClose” dataset as an candlestick chart. HINT: Use gvisCandlestickChart().

Exercise 2

Plot the the candlestick chart. HINT: Use plot().

Pie chart

It is quite simple to create a Pie Chart with googleVis. We will use the “CityPopularity” dataset. Look at the example below:
PieC <- gvisPieChart(CityPopularity)
plot(PieC)

Exercise 3

Create a list named “PieC” and pass to it the “CityPopularity” dataset as a pie chart. HINT: Use gvisPieChart().

Learn more about using GoogleVis in the online course Mastering in Visualization with R programming. In this course you will learn how to:

  • Work extensively with the GoogleVis package and its functionality
  • Learn what visualizations exist for your specific use case
  • And much more

Exercise 4

Plot the the pie chart. HINT: Use plot().

Gauge

The gauge chart is not very common compared with those we saw before but can be useful under certain circumstances. We will use the “CityPopularity” dataset. Look at the example:
GaugeC <- gvisGauge(CityPopularity)
plot(GaugeC)

Exercise 5

Create a list named “GaugeC” and pass to it the “CityPopularity” dataset as a gauge chart. HINT: Use gvisGauge().

Exercise 6

Plot the the gauge. HINT: Use plot().

The gauge gives you the ability to use colours in order to separate easier each area from the other. For example:
options=list(min=0, max=1200, blueFrom=900,blueTo=1200,greenFrom=600,
greenTo=900, yellowFrom=300, yellowTo=600,
redFrom=0, redTo=300, width=400, height=300)

Exercise 7

Separate the gauge to three areas by colours of your choice, from 0 to 900 and plot it. HINT: Use list().

Exercise 8

Set width to 400 and height to 300. HINT: Use width and height.

Intensity Map

The last chart we are going to see in this part is the Intensity Map.
It is quite simple to create an Intensity Map with googleVis. We will use the experimental data frame “co” we created before. Look at the example below:
IntensityC <- gvisIntensityMap(co)
plot(IntensityC)

Exercise 9

Create a list named “IntensityC” and pass to it the “co” dataset you just created as an intenisty map. HINT: Use gvisIntensityMap().

Exercise 10

Plot the the intensity map. HINT: Use plot().

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)