[R-sig-Geo] finding clusters of gridded points, distinguished by group

Malcolm Fairbrother m.fairbrother at bristol.ac.uk
Sun Dec 19 15:06:01 CET 2010


Dear all,

I have SpatialPointsDataFrame type data, with a few hundred observations scattered around the globe, and am trying to identify points that are both (a) neighbours, and (b) of the same group. In other words, within a group, there may be geographically non-contiguous clusters, and geographically contiguous clusters may contain one or more groups.

Here is a simple example to illustrate what I mean:

require(sp)
set.seed(1)
g <- SpatialPointsDataFrame(coords=expand.grid(x = 1:10, y = 1:10), data=data.frame(group=rep(LETTERS[10:1], each=10)))
g <- g[sample(1:100, size=30),]
plot(g, axes=T, pch=as.character(g$group))

I want to identify clusters of the *same* letter, where clusters are defined by *contiguity*.

I realise the following will get me a neighbours list:

dnearneigh(g, d1=0, d2=sqrt(2))

However, it's not clear to me how I might move from knowing about the properties of an individual point, to knowing about the identities of clusters containing variable numbers of points. And I have the added compication of wanting to parse out only neighbours that belong to the same group. Any assistance would be very much appreciated.

Thanks,
Malcolm



More information about the R-sig-Geo mailing list