In this recipe, we will learn how to plot country-wise data on a world map.
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)
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") ...