A chloropleth map displays divided geographical areas or regions that are coloured, shaded or patterned in relation to a data variable. It allows to study how a variable evolutes along a territory.
Note that several pitfalls are commonly observed in chloropleth map. The number of data point in each area remains unknown. If the variable you represent is linked to the area, you have to
normalize your variable first. (For example, you have to show a density of population and not a number of inhabitants that would be biased by the size of the area).
Chloropleth map from geoJSON format with ggplot2
Ggplot2 is my favourite way to make a static chloropleth map. In this post I show how to load geoJSON geographical data, link it with a numeric variable and plot it as a chloropleth. Another advantage of this method is that it allows to quickly transform your map in an interactive version with plotly (see further).
Chloropleth map from shape file format with plot() function
The exact same principle applies if your spatial data are in the shape file format. The next posts show how to read this format in R and display it using baseR functions. Note that I highly advise to use ggplot2 as proposed above. The procedure to read a shape file in R is also described extensively in chart #168.
Interactive Chloropleth map: with leaflet or plotly
If you display your map on the web, in a shiny application or in a Rmarkdown document, you probably want your map to be interactive. It would allow to zoom and hover a region to have further information. The best way to achieve this is to use the leaflet library, developed by RStudio. Another possibility is to use the ggplotly function of the plotly library. This is very handy since there is only one line of code to add to transform your ggplot2 chloropleth map to an interactive version.
Using the cartography library
Search the gallery