Skip to content
Prev 2709 / 29559 Next

Done!: Simultaneous interactive plot of hc dendrogram and geographic display

Well, thanks to the many inputs I've got, I've been able of
displaying a hc tree on one graphic display and, through the
use of identify.hc() click a branch and get the involved polygons
geographically displayed on another graphic window. It is inspired on 
the barplot example in the help page for identify.hc.

The normal situation would be clustering in the data slot
of the SpatialPolygonsDataFrame object. Here I'm using
a different table because I did not have the sps composition
for all the transects (polygons).

In the example below, ferns is a transects x sps data frame, where
the transects are some of the polygons in pols.

ferns.raup <- vegdist(ferns,method="raup")
ferns.hc <- hclust(ferns.raup)
plot(ferns.hc)
get(getOption("device"))()
nD <- dev.cur()
image(t1pc1s)
plot(boundary,lwd=2,col=2,add=T)
dev.set(dev.prev())
identify(ferns.hc, MAXCLUST=17,  FUN=function(k) {color=readline("Enter 
color: "); 
plot(polysubset(polys=pols,tabla=ferns,posic=k),add=T,lwd=3,border=color,col=color)}, 
DEV.FUN = nD)

The involved function is:

"polysubset" 
<-function(polys=pols,tabla=ferns,pos.nom="fern.class",posics=k)
{
	tabla <- tabla[posics,]
	sel <- match(names(tabla[,pos.nom]),polys at data$Site)
	polys[sel,]
}

Agus