Pär Engström
2012-Feb-28 10:04 UTC
[Rd] Unexpected behaviour for RowSideColors in function heatmap
Hello,
I have come across some unexpected behaviour of the function heatmap in the
stats package. This looks like a bug to me, but I might have misunderstood
something.
When calling the function in symmetric mode, the ColSideColors are plotted
correctly, but RowSideColors appear in reverse order. This code (modified from
the example on the help page) demonstrates the problem:
cU <- cor(USJudgeRatings)
sideCols <- rainbow(ncol(cU))
heatmap(cU, symm = TRUE, distfun = function(c) as.dist(1 - c),
ColSideColors=sideCols, RowSideColors=sideCols)
Reversing the RowSideColors argument does not solve the problem:
heatmap(cU, symm = TRUE, distfun = function(c) as.dist(1 - c),
ColSideColors=sideCols, RowSideColors=rev(sideCols))
I had a look at the the function code and found that this change fixes the
problem:
Replace
image(rbind(1L:nr), col = RowSideColors[rowInd], axes = FALSE)
with
image(rbind(if(revC) nr:1L else 1L:nr), col = RowSideColors[rowInd], axes
= FALSE)
I am using the current version of R for Mac OS X:
> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
Regards,
Pär Engström
Postdoctoral Fellow
EMBL European Bioinformatics Institute
Wellcome Trust Genome Campus
Hinxton, Cambridge, UK
[[alternative HTML version deleted]]
Kevin R. Coombes
2012-Mar-08 17:27 UTC
[Rd] Unexpected behaviour for RowSideColors in function heatmap
First, I can confirm this problem exists today, and can now vaguely
recall seeing it in previous version of R.
> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)
There is a bigger problem with heatmap.2 in the gplots package. Using
"symm=TRUE" with no other arguments causes it to *fail *to print one
of
the dendrograms:
> library(gplots)
> cU <- cor(USJudgeRatings)
> heatmap.2(cU, symm = TRUE)
Warning message:
In heatmap.2(cU, symm = TRUE) :
Discrepancy: Colv is FALSE, while dendrogram is `row'. Omitting
column dendogram.
In order to get the column dendrogram displayed using heatmap.2, you
must use "symm=TRUE, Colv=TRUE". So this *succeeds*:
> heatmap.2(cU, symm = TRUE, Colv=TRUE)
To make things worse, heatmap.2 *sometimes *gets the direction of the
column colors wrong. If you omit "Colv=TRUE", it leaves out the
column
dendrogram and gets one set of colors wrong. That, is, the following
command *fails* in two ways:
> sideCols <- rainbow(ncol(cU))
> heatmap.2(cU, symm = TRUE, distfun = function(c) as.dist(1 - c),
ColSideColors=sideCols, RowSideColors=sideCols)
If you include "Colv=TRUE", then it prints the dendrogram and gets
both
sets of colorbars correct. So the following command *succeeds*:
> heatmap.2(cU, symm = TRUE, Colv=TRUE, distfun = function(c) as.dist(1
- c),
+ ColSideColors=sideCols, RowSideColors=sideCols)
It is a separate esthetic question as to which diagonal axis should be
used for symmetry. When it works in heatmap.2, the "origin" is at the
bottom left. Since the dendrograms are printed on the top and left,
however, the symmetry would be easier to see/confirm if the origin were
put at the top left. One might be tempted to fit this by using
"revC=TRUE". However, this command *fails* because it gets the
colorbar
wrong:
> heatmap.2(cU, symm = TRUE, Colv=TRUE, revC=TRUE,
distfun = function(c) as.dist(1 - c),
ColSideColors=sideCols, RowSideColors=sideCols)
I am occasionally of the opinion that both "heatmap" and
"heatmap.2" are
too complex to be used reliably by mortals....
Kevin
On 2/28/2012 4:04 AM, Pär Engström wrote:> Hello,
>
> I have come across some unexpected behaviour of the function heatmap in the
stats package. This looks like a bug to me, but I might have misunderstood
something.
>
> When calling the function in symmetric mode, the ColSideColors are plotted
correctly, but RowSideColors appear in reverse order. This code (modified from
the example on the help page) demonstrates the problem:
>
> cU<- cor(USJudgeRatings)
> sideCols<- rainbow(ncol(cU))
> heatmap(cU, symm = TRUE, distfun = function(c) as.dist(1 - c),
> ColSideColors=sideCols, RowSideColors=sideCols)
>
> Reversing the RowSideColors argument does not solve the problem:
>
> heatmap(cU, symm = TRUE, distfun = function(c) as.dist(1 - c),
> ColSideColors=sideCols, RowSideColors=rev(sideCols))
>
> I had a look at the the function code and found that this change fixes the
problem:
>
> Replace
>
> image(rbind(1L:nr), col = RowSideColors[rowInd], axes = FALSE)
>
> with
>
> image(rbind(if(revC) nr:1L else 1L:nr), col =
RowSideColors[rowInd], axes = FALSE)
>
> I am using the current version of R for Mac OS X:
>
>> sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
>
> Regards,
>
> Pär Engström
>
> Postdoctoral Fellow
> EMBL European Bioinformatics Institute
> Wellcome Trust Genome Campus
> Hinxton, Cambridge, UK
>
>
>
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
[[alternative HTML version deleted]]