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.
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
As you already know, the first thing you have to do is install and load the googleVis package with:
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 scatter chart with googleVis. We will use the
cars dataset. Look at the example below:
ScatterC <- gvisScatterChart(cars)
Create a list named “ScatterC” and pass to it the
cars dataset as a scatter chart. HINT: Use
Plot the the scatter chart. HINT: Use
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:
Name your chart “Cars”, your chart’s vAxis “speed”, your chart’s hAxis “dist” and plot the chart. HINT: Use
You can adjust the size with
Set your chart’s
width to 600 and
height to 300.
You can deactivate your chart’s
legend if you set it to “none”.
Deactivate your chart’s
Point size & Line width
You can determine the size of the chart’s points with
pointsize and also choose to unite them with line with
linewidth. For example:
Set point size to 3 and line width to 2.
Another amazing type of chart that googleVis provides is the bubble chart. You can create a simple Bubble Chart of the
Fruits dataset like this:
BubbleC <- gvisBubbleChart(Fruits)
Create a list named “BubbleC” and pass to it the
Fruits dataset as a bubble chart. HINT: Use
Plot the chart. HINT: Use
Bubble Chart’s Features
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
head(Fruits) you can easily recognize the numeric variables of your dataset. Then you can use them like this:
BubbleC <- gvisBubbleChart(Fruits,idvar="VAR1",
Find the numeric variables of
Fruits, then set “Fruit” as
idvar, “Sales” as
xvar, “Expenses” as
yvar, “Year” as
colorvar and “Profit” as
sizevar and plot your chart. HINT: Use
You can also adjust the minimum and maximum number of hAxis and vAxis that you want to be displayed. Look at the example below:
Set your hAxis range from 70 to 130 and your vAxis range from 50 to 100.