Cluster.R

From Organic Design wiki
Revision as of 03:24, 16 November 2006 by Sven (talk | contribs) (another version)

clusterPlot <- function(x, dmethod = "euclidian", hmethod = "complete", ...) {

 oldpar <- par(mfrow=c(2,1)) 
 xDist  <- dist(x, method = dmethod)
 xClust <- hclust(xDist, method = hmethod)
 plclust(xClust, sub="")
 
 image(list(x = 1:nrow(x), y = 1:ncol(x), z = x[clust$order,]), 
     col=heat.colors(nrow(x)), ...)
 par(oldpar)
 invisible()

}

clusterPlot(x)

  1. Test

x <- matrix(rnorm(40), nc=4) colnames(x) <- LETTERS[1:4] rownames(x) <- letters[1:10] clusterPlot(x)