Choropleth Map





A choropleth map displays divided geographical areas or regions that are coloured in relation to a numeric variable. This section provides many examples build with R. It focuses on the leaflet package for interactive versions, and the ggplot2 for static ones.

Choropleth map with ggplot2

ggplot2 is my favourite way to make a static choropleth map. In this post I show how to load geoJSON geographical data, link it with a numeric variable and plot it as a choropleth. Another advantage of this method is that it allows to quickly transform your map in an interactive version with plotly (see further).





Choropleth map with ggiraph

ggiraph is a package that makes super easy to create interactive charts, and map are not an exception.

The chart below automatically maps the countries from the map to the other charts with some nice hover effects thanks to CSS, which make it easy to understand and intuitive to interpret.

Try to hover!

Code



Choropleth map in base R

No specific library is needed to build a choropleth map once the geospatial object is loaded in R. The examples below explain how to build a color palette and attribute a color to each region, according to its numeric value.





Interactive choropleth map with leaflet

The leaflet package allows to build interactive map directly from R. On the following choropleth map it is possible to zoom and hover a country to gets more details about it. Read the tutorial.

Code



Choropleth map with the cartography package.

Best R Choropleth Maps

The web is full of astonishing R charts made by awesome bloggers. The R graph gallery tries to display some of the best creations and explain how their source code works. If you want to display your work here, please drop me a word or even better, submit a Pull Request!

Related chart types


Map
Choropleth
Hexbin map
Cartogram
Connection
Bubble map