In part 6 of this series we are going to see some amazing geographical 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.
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 Geo Chart with googleVis. We will use the “Exports” dataset. First let’s take a look at it with
head(Exports). As you can see there are three variables (“Country”, “Profit”, “Online”) which we are going to use later.
Look at the example below to create a simple geo chart:
Create a list named “GeoC” and pass to it the “Exports” dataset as a geo chart. HINT: Use gvisGeoChart().
Plot the the geo chart. HINT: Use
Furthermore you can add much more information in your chart by using the
colorvar options to color the countries according to the their profit. Look at the example below.
Color the countries of your geo chart according to their profit and plot it. HINT: Use
It is quite simple to create a Google Map with googleVis. We will use the “Andrew” dataset. First let’s take a look at it with
head(Andrew) to see its variables. Look at the example below to create a simple google map:
GoogleMap <- gvisMap(Andrew)
Create a list named “GoogleMap” and pass to it the “Andrew” dataset as a google map. HINT: Use
Plot the the google map. HINT: Use
As you can see there ane no data points on it as we did not select something yet. We have to select the latitude and longtitude variables for the dataset like the example below.
GoogleMap <- gvisMap(Andrew,"LatLong" )
Display the map by addind the “LatLong” variable to your list and plot it.
Display the “Tip” variable on your google map just like you displayed the “LatLong” and plot it.
There are some useful options that
gvisMap() provides to you that can enhance your map. Check the example below.
Deactivate the Tip information from your map, plot the map and then enable it again. HINT: Use
useMapTypeControl and plot the map.
mapType by default to “terrain” and plot the map.