Difference between revisions of "Cluster.R"

From Organic Design wiki
m (another version)
(Adding missing arg)
Line 1: Line 1:
clusterPlot <- function(x, dmethod = "euclidian", hmethod = "complete", ...) {
+
clusterPlot <- function(x, dmethod = "euclidian", hmethod="complete", ...) {
   oldpar <- par(mfrow=c(2,1))  
+
   oldpar <- par(mfrow=c(2,1))
   xDist <- dist(x, method = dmethod)
+
   xDist <- dist(x, method=dmethod)
   xClust <- hclust(xDist, method = hmethod)
+
 
 +
# 1) Tree dendrogram
 +
   xClust <- hclust(xDist, method=hmethod)
 
   plclust(xClust, sub="")
 
   plclust(xClust, sub="")
 
    
 
    
   image(list(x = 1:nrow(x), y = 1:ncol(x), z = x[clust$order,]),  
+
# 2) Image plot... 
      col=heat.colors(nrow(x)), ...)
+
   image(x = 1:nrow(x), y = 1:ncol(x), z = x[xClust$order, ], col=heat.colors(nrow(x)), ...)
 
   par(oldpar)
 
   par(oldpar)
 
   invisible()
 
   invisible()
 
}
 
}
 
clusterPlot(x)
 
  
 
# Test
 
# Test

Revision as of 03:25, 16 November 2006

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

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

}

  1. Test

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