Can anyone suggest an algorithm to generate a heatmap for visualising point diversity? An example application would be for mapping areas of high species diversity. For some species, every single plant has been mapped, resulting in a high point count, but with very little meaning in terms of the diversity of the area. Other areas genuinely have high diversity.

Consider the following input data:

x    y      cat
0.8  8.1    B
1.1  8.9    A
1.6  7.7    C
2.2  8.2    D
7.5  0.9    A
7.5  1.2    A
8.1  1.5    A
8.7  0.3    A
1.9  2.1    B
4.5  7.0    C
3.8  4.0    D
6.6  4.8    A
6.2  2.4    B
2.2  9.1    B
1.7  4.7    C
7.5  7.3    D
9.2  1.2    A

and resulting map:

grid plot

In the upper left quadrant, there is a highly diverse patch, while in the lower right quadrant, there is an area with high point concentration, but low diversity. Two ways to visualise the diversity could be to use a traditional heatmap, or to count the number of categories represented in each polygon. As the following images show, these approaches have limited use, since the heatmap shows the greatest intensity in the lower right, while the binning approach would look exactly the same if there were only one category (this could be addressed by increasing the size of the polygon bins, but then the result becomes unnecessarily granular).

heatmap enter image description here

One approach I thought of to do this would be to prime a traditional heatmap algorithm by the number of points of different categories within a defined radius, and then using that count as the weight for the point when generating the heatmap. However, I think this might be prone to unwanted artefacts, like mutual reinforcement leading to very sharp results. Also, closely mapped points of the same type would continue to show up as high concentrations, just not to the same extent.

Another approach (probably better but more computationally expensive) would be:

  1. Calculate the total number of categories in the dataset
  2. For each pixel in the output image:
    • For each category:
      • calculate the distance to the nearest representative point (r) [probably limiting by some radius beyond which influence is negligible]
      • add a weighting proportional to 1/r2

Are there already algorithms that I'm not aware of to do this, or other ways to visualise diversity?


Following Tomislav Muic's suggestion, I have calculated the heatmaps for each category, and normalised them using the following formula (QGIS raster calculator):

((heatmap_A@1 >= 1) + (heatmap_A@1 < 1) * heatmap_A@1) +
((heatmap_B@1 >= 1) + (heatmap_B@1 < 1) * heatmap_B@1) +
((heatmap_C@1 >= 1) + (heatmap_C@1 < 1) * heatmap_C@1) +
((heatmap_D@1 >= 1) + (heatmap_D@1 < 1) * heatmap_D@1)

with the following result (comments under his answer): normalised sum

  • 1
    Your second approach looks Ok, this is mostly a statistics problem, so I'd start looking at corresponding R routines at CRAN. Would experiment with different grid sizes, though, and look for 'official' measures of biodiversity to avoid re-inventing the wheel. Mar 26, 2013 at 3:21

1 Answer 1


Try making a heatmap for each separate category.

Then sum the heatmaps and normalize them using number of categories.

This might be worth exploring.

  • I have added a visualisation to my question based on this suggestion, and the result looks good! The disadvantage is that if you're dealing with hundreds or thousands of categories, storing all of those rasters is going to be a problem. Mar 26, 2013 at 9:40
  • Come to think of it, that wouldn't be a problem if you added each new heatmap to the composite heatmap after each category. The question is then which approach would be computationally faster to implement - raster sums or pixel-by-pixel calculation. Mar 26, 2013 at 9:47
  • 1
    I'm afraid this answer has nothing to do with diversity. In the resulting sum (and normalization) a very dense area with multiple groups would look the same as an area not as dense but with one group.
    – Andy W
    Mar 26, 2013 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.