[R] Flipping a heatmap

Martin Maechler maechler at stat.math.ethz.ch
Thu Sep 11 17:33:03 CEST 2003

After some off-line discussion I want to correct my earlier
It's clear (even to me ;-) that the idea of reordering columns
(and rows simultaneously for symmetric matrices) and then
image()ing is very appropriate for correlation matrices.
BTW, this has been quite an old idea, going back to
Bertin (1983) and probably much longer.

What I rather meant to say was that currently heatmap() isn't
setup to support this use very well.  But even there I wasn't
quite correct, since you can achieve quite a bit by using the
`Rowv' and `Colv' arguments.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch>
>>>>>     on Thu, 11 Sep 2003 14:43:21 +0200 writes:

>>>>> "AndyL" == Liaw, Andy <andy_liaw at merck.com>
>>>>>     on Thu, 11 Sep 2003 07:46:16 -0400 writes:

    AndyL> My feeling is that heatmap is not the right thing to
    AndyL> use on a correlation matrix.  
    MM> definitely.

    AndyL> The heatmap function expects a data matrix, and does
    AndyL> a two-way clustering of cases and variables.  It
    AndyL> tries to rearrange the rows and columns so that
    AndyL> similar colors are closer together.  This obviously
    AndyL> will not work for a correlation matrix.  (The
    AndyL> rearrangement is one of several enhancements that
    AndyL> Robert/Martin added to my original attempt.)

    AndyL> If you really want to do it, you may try to find my
    AndyL> original naive version of the heatmap function, which
    AndyL> I posted to the Bioconductor mailing list earlier
    AndyL> this year.  That does not do any rearragement.

    MM> Thank you, Andy.  
    MM> Further note that the upcoming version of R will also allow the
    MM> option of *not* doing any reordering. 

    MM> But even then, heatmap() is not quite appropriate for
    MM> correlation matrices.

    AndyL> HTH,
    AndyL> Andy

    >>> -----Original Message-----
    >>> From: David Khabie-Zeitoune [mailto:dave at evocapital.com] 
    >>> Sent: Thursday, September 11, 2003 4:04 AM
    >>> To: r-help at stat.math.ethz.ch
    >>> Subject: [R] Flipping a heatmap
    >>> Hi
    >>> I am using the heatmap function in package mva to look at 
    >>> large correlation matrices visually. Is there any way to 
    >>> "flip" the output of heatmap plot left-right so that, if 
    >>> presented with a correlation matrix, it plots the unity 
    >>> elements in the correlation matrix along a diagonal from top 
    >>> left to bottom right?
    >>> For example:
    >>> library(mva)
    >>> x = matrix(rnorm(1000), ncol=10)
    >>> z = cor(x)
    >>> heatmap(z)
    >>> Heatmap calls image, and I've found ways to do it with image e.g:
    >>> image(z[1:10,10:1]) 
    >>> will plot things the "right" way round, but
    >>> heatmap(z[1:10,10:1]) 
    >>> does not.
    >>> Any help much appreciated.
    >>> Cheers,
    >>> Dave

More information about the R-help mailing list