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
My feeling is that heatmap is not the right thing to use on a correlation matrix. The heatmap function expects a data matrix, and does a two-way clustering of cases and variables. It tries to rearrange the rows and columns so that similar colors are closer together. This obviously will not work for a correlation matrix. (The rearrangement is one of several enhancements that Robert/Martin added to my original attempt.) If you really want to do it, you may try to find my original naive version of the heatmap function, which I posted to the Bioconductor mailing list earlier this year. That does not do any rearragement. HTH, 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 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Thanks to everyone who replied on this subject. Clearly, two rows of the correlation matrix which have similar numerical entries represent two variables which have similar correlations with the other variables. Therefore clustering using a distance metric (e.g. dist) defined on the rows (or equivalently columns) of the correlation matrix produces an ordering which lumps together correlated variables. This had been my original thinking (if a little fuzzy), but I've decided now to do the clustering on the data matrix directly and just do an image plot of the resulting re-ordered correlation matrix. If any one else has good ideas about how to visualise correlation structures in large correlation matrices, I'd love to hear them, on- or off-line. -----Original Message----- From: Duncan Murdoch [mailto:dmurdoch at pair.com] Sent: 11 September 2003 13:53 To: r-help at stat.math.ethz.ch Subject: Re: [R] Flipping a heatmap On Thu, 11 Sep 2003 07:46:16 -0400, you wrote:>My feeling is that heatmap is not the right thing to use on a >correlation matrix. The heatmap function expects a data matrix, and >does a two-way clustering of cases and variables. It tries to >rearrange the rows and columns so that similar colors are closer >together. This obviously will not work for a correlation matrix.There are several different ways you might organize the rows and columns of a correlation matrix, but rearranging it to put equal correlations together sounds like one sensible idea. You'd probably want row and column labels rather than the dendrogram heatmap() puts on, but other than that, it seems like a nice idea to me. Duncan Murdoch ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
On Thu, 11 Sep 2003 07:46:16 -0400, Duncan Murdoch wrote>>>My feeling is that heatmap is not the right thing to use on a correlation >>>matrix. The heatmap function expects a data matrix, and does a two-way >>>clustering of cases and variables. It tries to rearrange the rows and >>>columns so that similar colors are closer together. This obviously will not >>>work for a correlation matrix. > > >There are several different ways you might organize the rows and >columns of a correlation matrix, but rearranging it to put equal >correlations together sounds like one sensible idea. You'd probably >want row and column labels rather than the dendrogram heatmap() puts >on, but other than that, it seems like a nice idea to me. > >Duncan Murdoch >My American Statistician paper, @Article{Friendly:02:corrgram, author = "M. Friendly", year = "2002", journal = TAS, volume = 56, number = 4, pages = "316--324", title = "Corrgrams: Exploratory displays for correlation matrices", url = "http://www.math.yorku.ca/SCS/Papers/corrgram.pdf", } defines a simple scheme for reordering a correlation matrix (or R^-1, for conditional independence) based on angles of the first two eigenvectors. A variety of rendering schemes is also described. There's a SAS macro at * Doc: http://www.math.yorku.ca/SCS/sasmac/corrgram.html * -- Michael Friendly Email: friendly at yorku.ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA