Statistical Maps with R

INTRODUCTION

Maps are one of the most widely used forms of data visualization. With the advancement in Geographic Information Systems and technology, it has become possible to collect more precise data and visualize it to reveal trends and conclusions, which seemed impossible before. It is possible to aggregate data based on the geographic location and study the emerging patterns, understand the relationships between two regions, and observe the changing pattern over time. This document will help you to create interactive maps using the googleVis package.

Getting ready

We need to install and load the googleVis package in R:

install.packages("googleVis")

library(googleVis)

Next we will get our data file. Our data is related with the global warming. It gives 100 most greenhouse gas emitting countries in 2013 in million
metric tons for various years.

Reading the data file

We will first import the ghg.csv file, which contains our data in R, using the read.csv() function:

emisn = read.csv("ghg.csv")

We can examine the data using the head(emisn) function or View(emisn)

head(emisn)

View(emisn)

 

Getting the map

The visualization is generated in R using the gvisGeoMap() function and the same is displayed in a browser using the plot() function:

emitchart = gvisGeoChart(emisn, locationvar = "Country", sizevar = "Emission_in_2010")

plot(emitchart)

Also, try

emitmap = gvisGeoMap(emisn, locationvar = "Country", numvar = "Emission_in_2010")

plot(emitmap)

The first argument under the gvisGeoMap() and gvisGeoChart() functions relates to the data that is defined as a data frame known as emisn. The second argument is locationvar, which can be specified using many different options. In our recipe, the column containing the country names is
passed as locationvar. The sizevar and numvar argument corresponds to the column containing our data.

Critical thinking

Do you think that it is reasonable to use the total emission for the countries? If not what would you suggest? Modify the data and add more information to produce more reasonable maps.