Re: [R] Cutting heatmap dendrogram

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Wed 21 Jul 2004 - 20:25:21 EST

>>>>> "Sean" == Sean Davis <sdavis2@mail.nih.gov> >>>>> on Wed, 21 Jul 2004 06:01:33 -0400 writes:

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

this was probably helpful but didn't really answer the original question.

One thing you (Paul) should do is to "cut()" the dendrogram instead of "cutree()"ing the hclust result and then *pass* the cut()ed dendrogram directly to heatmap().

I'm interested to hear if that works (haven't got time to experiment with that just now).

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

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

I disagree. This was a question about heatmap() an R function of more general use than microarrays.
I would have found it "wrong" to ask this question on the bioconductor mailing list.

Martin Maechler

    Sean> Sean

    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@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 Received on Wed Jul 21 20:37:02 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:09 EST