A cartogram is a  map in which the geometry of regions is distorted in order to convey the information of an alternate variable. In this example, we are going to draw a map of Africa where the size of each country is distorted proportionally to its population.

First of all, you need to understand what a geospatial object is, and how to plot it with R. See the background map section of the gallery!

Let’s use the maptools library which provide a geospatial object with the Africa’s boundaries. Note that you can get a similar object from a shapefile, or from a geojson file!

We can plot the boundaries using the plot() function:





The geospatial object has a ‘data slot‘: an attached data frame that provides several information for each region. It notably gives the population of each country in 2005. We can thus use the cartogram library to distort the size of each country, proportionally to this column. The new geospatial object we get can be drawn with the same plot function!

See how Nigeria is now bigger?



Of course, it is possible to custom the representation. Since we have a spatial object, all the techniques described in the map, chloropleth and hexbin sections will work here to. Let’s use ggplot2 to add some color, title, legend, background … We now have a nice cartogram chloropleth map of Africa!




Make a search



Leave a Reply

Notify of