[R-sig-Geo] creating polygons of clusters of points?

Hans Ekbrand hans at sociologi.cjb.net
Fri Apr 23 16:37:38 CEST 2010


How to create nice polygons from a number of clusters?

I have sorted list of clusters representing hot-spots

> sorted.list.of.clusters
 [1]  7  1 11  9 26  2  5 10 33 40 18 28 37 20 30 47 53

whereas my.cluster holds the classification of events (criminal
fire-setting) to clusters:

head(my.cluster, 100)
  [1]  1  2  3  3  4  5  6  7  8  5  9 10 11 12  1 13  2 14 15 10 16 17  5 13  7  7 18 19 18 20 20  2 21 16 22 18 10  1
 [39]  9 23  4  7 24  9  9  7  7  5  2 11 25 12  7  7 26 27 13  7  7 28 18 28 29  9  2  5 30 11 31 14 18  1 32 26  2 31
 [77] 29 33  2 34  2 26 35 36  7  2 35 37 26 38 11  2 11 26 30  7  4 11  8 11

> number.of.fires.at.hotspots <- sapply(sorted.list.of.clusters, function(x) {length(which(my.cluster == x))})
> number.of.fires.at.hotspots
 [1] 44 39 38 32 22 21 21 21 15 15 14 14 14 12 12 12 12

The "SpatialPointsDataFrame" object clust.geo.test holds the events.

A list coordinates of the events of each cluster is generated with:

> sapply(sorted.list.of.clusters, function(x) {clust.geo.test at coords[which(my.cluster == x),]})
[[1]]
           Ost    Nord
 [1,] 322737.4 6406939
 [2,] 323104.9 6406968
 [3,] 323104.9 6406968
...

[[2]]
           Ost    Nord
 [1,] 315359.9 6393110
 [2,] 315177.0 6394031
 [3,] 314697.8 6394565
...

And I can plot the points in the hot-spots with

> plot(sdn)
> sapply(sorted.list.of.clusters, function(x) {plot(clust.geo.test[which(my.cluster == x),], add = T)})

But would like to plot each cluster as a polygon, ideally filled with
darker colors for clusters with higher number of fires.

I guess I need to create polygons for each cluster and then plot each
polygon. How do you do that?

For your convenience I have created a RData object containing the
objects refered to above and uploaded to this URI

http://sociologi.cjb.net/temp/to-polygons-help.RData, so 

print(load(url("http://sociologi.cjb.net/temp/to-polygons-help.RData")))
plot(sdn)
sapply(sorted.list.of.clusters, function(x) {plot(clust.geo.test[which(my.cluster == x),], add = T)})

would get you to the point I am now.

Hans Ekbrand
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100423/bc728e00/attachment.bin>


More information about the R-sig-Geo mailing list