# Devide heatmap into meaningful clusters

I created a heatmap containing population density data. Now I want to figure out the hotspots of this heat map. In other words: Where are the biggest population densities in my map?

My first thought: Take a threshold and identify the biggest population densities. But somehow this method is a little too "random" for me, because its only me who decides where this threshold will be. I am searching for a method (e.g. automatic clustering) who will devide my density map into clusters and also gives an explanation why it took these clusters.

I am normally working with R, but I am also happy for solutions in another programm.

P.S.: For a better understanding I added the picture. White parts show high population density, black parts a low density. There are are some NULL Values. • Where's your data coming from? The problem is that once you've computed a "heatmap" of your population density you may have thrown away about 90% of the information just to create a pretty map in pretty rainbow shades. Do you have the point locations of all the individuals in your population? Do you have village locations and total village populations? It would be much better to start with the underlying data and construct a meaningful statistical question from that rather than trying to draw "significant" contours round a density surface. – Spacedman Nov 2 '15 at 8:11
• I have point locations, which show the population in each 100x100 cell of the area. All the data is stored in a point layer, which is distributed in the mentioned 100x100 distances. – Peter Nov 2 '15 at 9:38
• So its actually a 100x100 grid raster of population counts? – Spacedman Nov 2 '15 at 10:08
• Yes, this is true. – Peter Nov 2 '15 at 10:39

...and here's where actual spatial statistics enter the game.

Spatial inferential statistics will throw away the subjectivity you just described. I'm an ArcGIS user, so my answer will be based on that.

A probable solution to your problem is to apply a Hot Spot Analysis (Getis-Ord Gi*). Before this, you may need to find the optimum scale of clustering by applying the global Moran's I algorithm. In arcMap it's called Spatial Autocorrelation (Moran's I). Depending on what kind of spatial data you have (points or polygons), you have to define the spatial relationships between your objects.

For example, if you have points you have to define the radius of influence (distance band). On the other hand, if you have polygons you have to define wether the polygons that will be processed will have common edges, boundaries etc.

I also see no meaning in applying any clustering to your density map (raster data). Since it's subjective, I think that the clustering of the raster surfae will be subjective too.

• The one problem with your recommendations is that significant autocorrelation was introduced into the random field when the density analysis was performed. As such, any evaluation of autocorrelation would be a function of the algorithm and coefficients used in deriving density and not actual spatial process. – Jeffrey Evans Nov 2 '15 at 2:48
• This is why I didn't recommend statistical analysis to the density surface he produced, since it' s biased whatever algorithm he used to produce it. Hence, I think he should apply inferential spatial statistics to the evenly distributed points he has. Why not? He says "...All the data is stored in a point layer, which is distributed in the mentioned 100x100 distances..." – KonstaNtie Nov 2 '15 at 14:46
• Yes. Actually that's something what I was searching for! As I have ArcGIS anyway I will try it and make sure it really fits to my problem. – Peter Nov 2 '15 at 18:41
• @Peter I hope you accomplish your goal – KonstaNtie Nov 2 '15 at 19:32
• I can use this a a solution for my problem, as it gives me a reliable threshold (reliable because it gives me an significance niveau). As I understood this method is often used to explore hotspots of crimes in a certain area. The thought to use this principle as a method to explore hotspots in population density seems very locical to me. P.S. If you don't have ArcGIS, you might like the "Rooks Case "Add-In for excel: lpc.uottawa.ca/data/scripts A good explantion fior the tool can be found here: ucl.ac.uk/jdi/events/int-CIA-conf/ICIAC11_Slides/… – Peter Nov 2 '15 at 20:17

You could display the data as volume contours (isopleths). There is a function "raster.vol" in the spatialEco package that will allow you to calculate a specified volume. You could then plot the volumes or use each volume to extract ranges for class breaks in the continuous density data.

Here we calculate a isotropic kernel density estimate on the bei tree data.

``````library(spatstat)
library(spatialEco)
library(raster)
data(bei)

d <- density(bei)
d <- raster(d)
plot(d)
``````

Here we calculate volumes in 10% increments. Keep in mind that the volumes nest where 10 will be within 20; 10 and 20 will be within 30, etc... In this case the d.10 raster would be the 10% volume of the data and represents the highest concentration of data values.

``````d.90 <- raster.vol(d, p = 0.90)
d.80 <- raster.vol(d, p = 0.80)
d.70 <- raster.vol(d, p = 0.70)
d.60 <- raster.vol(d, p = 0.60)
d.50 <- raster.vol(d, p = 0.50)
d.40 <- raster.vol(d, p = 0.40)
d.30 <- raster.vol(d, p = 0.30)
d.20 <- raster.vol(d, p = 0.20)
d.10 <- raster.vol(d, p = 0.10)
``````

We can add the volumes to plot the isopleth contours.

``````d.vol <- d.90 + d.80 + d.70 + d.60 + d.50 + d.40 + d.30 + d.20 + d.10

par(mfrow=c(2,1))
plot(d)
plot(d.vol, col = colorRampPalette(c("blue", "red"))(9), legend = FALSE)
legend("topright", legend=c("10%", "20%", "30%", "40%", "50%", "60%",
"70%", "80%", "90%"), fill = rev(colorRampPalette(c("blue", "red"))(9)),
bg = "white", cex = 0.70)
``````