O'Reilly logo

R: Data Analysis and Visualization by Ágnes Vidovics-Dancs, Kata Váradi, Tamás Vadász, Ágnes Tuza, Balázs Árpád Szucs, Julia Molnár, Péter Medvegyev, Balázs Márkus, István Margitai, Péter Juhász, Dániel Havran, Gergely Gabler, Barbara Dömötör, Gergely Daróczi, Ádám Banai, Milán Badics, Ferenc Illés, Edina Berlinger, Bater Makhabel, Hrishi V. Mittal, Jaynal Abedin, Brett Lantz, Tony Fischetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Plotting global data by countries on a world map

In this recipe, we will learn how to plot country-wise data on a world map.

Getting ready

We will use a few different additional packages for this recipe. We need the maps package for the actual drawing of the maps, the WDI package to get the World Bank data by countries, and the RColorBrewer package for color schemes. So, let's make sure these packages are installed and loaded:

install.packages("maps")
library(maps)
install.packages("WDI")
library(WDI)
install.packages("RColorBrewer")
library(RColorBrewer)

How to do it...

There are a lot of different data we can pull in using the world bank API provided by the WDI package. In this example, let's plot some CO2 emissions data:

colours = brewer.pal(7,"PuRd") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required