[R] Cutting heatmap dendrogram

Sean Davis sdavis2 at mail.nih.gov
Wed Jul 21 12:01:33 CEST 2004


Paul,

You can certainly get a heatmap of a subset of your data by simply 
subsetting.  If you have a group of genes obtained from cutree, simply 
do a heatmap on that set of genes.  If you obtain a set of genes, say 
A, and want to do a heatmap on that subset, simply do 
heatmap(as.matrix(data[A,])) where A contains either a logical vector 
or indices for the genes of interest.  The dendrograms will be 
generated for those samples and genes based on the subset of data.  You 
could, of course, pass in the sample dendrogram from the original 
clustering of all genes if you like.

It sounds like you are aiming for interactive clustering, which R does 
not do well.  Consider using an external viewer such as the 
cluster/treeview combo or the TIGR clustering program (can't remember 
name).

Finally, for future reference, it is probably worthwhile posting 
microarray questions to the Bioconductor mailing list rather than 
R-Help.

Sean

On Jul 20, 2004, at 9:39 PM, Paul Boutros wrote:

> 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());
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list