Difference between revisions of "Cluster.R"
From Organic Design wiki
(Adding missing arg) |
(Add alt naming functionality) |
||
Line 1: | Line 1: | ||
− | clusterPlot <- function(x, dmethod = "euclidian", hmethod="complete", ...) { | + | clusterPlot <- function(x, rowNames = NULL, dmethod = "euclidian", hmethod="complete", ...) { |
oldpar <- par(mfrow=c(2,1)) | oldpar <- par(mfrow=c(2,1)) | ||
+ | |||
+ | if(is.character(rowNames) & (length(rowNames) == nrow(x))) { | ||
+ | rownames(x) <- rowNames | ||
+ | } | ||
xDist <- dist(x, method=dmethod) | xDist <- dist(x, method=dmethod) | ||
Line 18: | Line 22: | ||
rownames(x) <- letters[1:10] | rownames(x) <- letters[1:10] | ||
clusterPlot(x) | clusterPlot(x) | ||
+ | clusterPlot(x, rowNames = LETTERS[1:10]) |
Revision as of 23:17, 7 December 2006
clusterPlot <- function(x, rowNames = NULL, dmethod = "euclidian", hmethod="complete", ...) {
oldpar <- par(mfrow=c(2,1))
if(is.character(rowNames) & (length(rowNames) == nrow(x))) { rownames(x) <- rowNames } xDist <- dist(x, method=dmethod)
- 1) Tree dendrogram
xClust <- hclust(xDist, method=hmethod) plclust(xClust, sub="")
- 2) Image plot...
image(x = 1:nrow(x), y = 1:ncol(x), z = x[xClust$order, ], col=heat.colors(nrow(x)), ...) par(oldpar) invisible()
}
- Test
x <- matrix(rnorm(40), nc=4) colnames(x) <- LETTERS[1:4] rownames(x) <- letters[1:10] clusterPlot(x) clusterPlot(x, rowNames = LETTERS[1:10])