Shaded contour lines or Tanaka method with R

[edit]The tanaka package, released after this post, facilitates the creation of such maps[/edit].

The following post, Tanaka method or how to make shaded contour lines on blog, explains clearly and thoroughly what shaded contour lines are and how to draw them with QGIS.
How hard would it be to implement this method with R?


This method is used to enhance the elevation visibility on raster images, so the first step consists in getting or building a raster image. Then we have to extract contour polygons. The last step consists in displaying successive layers of these contour polygons.

In this example I build a raster of the smoothed population density of Paris using IRIS units, which are a french sub-municipal statistical division.

Then I use the rasterToContourPoly() function from SpatialPosition to extract contour polygons based on the density raster.

I finally iterate over each levels of contour and plot three contour layers at each iteration: one with a north-west shift and a light color, a second with a south-east shift and a dark color, the third is plotted in place and colored according to the color palette.

Here is the final map on the smoothed population density in Paris:

You can find the full script used to build this map here.

The last map use the same technique on a more classical elevation dataset on Martinique.

Full script for this map here.

Citer ce billet
Timothée Giraud (2018, 12 juillet). Shaded contour lines or Tanaka method with R. R Géomatique. Consulté le 23 mai 2024, à l’adresse

4 réflexions sur « Shaded contour lines or Tanaka method with R »

  1. Hello,
    this is a great tool! Is there a chance that you update the Martinique map script? I get an error saying that the rasterToContourPoly() function is unknown. Using the isopoly() function, it gives an error as well, saying that the layer names are invalid.

    Best wishes

      1. Dear Timothee,
        I saw that you suggest using the tanaka package. What I liked on the old script was that I could plot the data through base R. As far as I can see, the tanaka package has its own plotting function and I prefer adding just another layer to my existing plot using the “older” version.

        Best wishes

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.