[R] Cutting heatmap dendrogram

Paul Boutros Paul.Boutros at utoronto.ca
Wed Jul 21 03:39:21 CEST 2004


Hello,

I've been clustering my data using hclust and cutting the resulting tree
with cutree.  Separately, I visualize the clusterings with heatmap.  Is it
possible to have the dendrogram on the heatmap reflect the cutree results?
That is, instead of having one large dendrogram, it would have 4 or 25 in
the example below.  Any guidance on if that's possible or not, and what
kinds of commands I should be looking into would be very much appreciated.
I'm using R 1.9.0 on Windows XP.

Thanks!
Paul

# load libraries
library(stats);

# working copy of data
set1 <- as.matrix(data);
set2 <- t(set1);

# genes
genes.distance <- as.dist(1-cor(set2));
genes.clusters <- hclust(genes.distance);
genes.dendrogr <- as.dendrogram(genes.clusters);

# samples
samples.distance <- as.dist(1-cor(set1));
samples.clusters <- hclust(samples.distance1);
samples.dendrogr <- as.dendrogram(samples.clusters1);

# cut the trees
samples.members  <- cutree(samples.clusters, k=4);
genes.members    <- cutree(genes.clusters,   k=25);

# heatmap colouring
my.colors <- function(n = 20, low.col = 0.35, high.col=1, saturation = 0.85)
{
  if (n < 2) stop("n must be greater than 2")
  n1 <- n%/%2
  n2 <- n - n1
  c(hsv(low.col, saturation, seq(1,0,length=n1)),
     hsv(high.col, saturation, seq(0,1,length=n2)))
}

# make the heatmap
hv <- heatmap(as.matrix(data), Rowv=genes.dendrogr, Colv=samples.dendrogr,
col=my.colors());




More information about the R-help mailing list