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.
For other parts follow the tag googleVis
Package & Data frame
As you already know, the first thing you have to do is install and load the googleVis package with:
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"),
NOTE: The charts are created locally by your browser. In case they are not displayed at once press F5 to reload the page.
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,
Create a list named “CandleC” and pass to it the “OpenClose” dataset as an candlestick chart. HINT: Use
Plot the the candlestick chart. HINT: Use
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)
Create a list named “PieC” and pass to it the “CityPopularity” dataset as a pie chart. HINT: Use
Plot the the pie chart. HINT: Use
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)
Create a list named “GaugeC” and pass to it the “CityPopularity” dataset as a gauge chart. HINT: Use
Plot the the gauge. HINT: Use
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)
Separate the gauge to three areas by colours of your choice, from 0 to 900 and plot it. HINT: Use
width to 400 and
height to 300. HINT: Use
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)
Create a list named “IntensityC” and pass to it the “co” dataset you just created as an intenisty map. HINT: Use
Plot the the intensity map. HINT: Use
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below