Dear all, I've been trying to find how to compare tow different heatmaps but I'm having trouble getting the colors bar to be the same. I'm doing something like the following: library(gplots) dat<-cor(matrix(rnorm(100, m=10), nrow=10)) mat<-cor(matrix(rnorm(100), nrow=10)) dev.new() heatmap.2(mat, Rowv=NA, Colv=NA, col=redgreen(75), symm=TRUE, trace="none", dendrogram="none", main = paste("Correlation Matrix for time delay at ", sep="")) dev.new() heatmap.2(dat, Rowv=NA, Colv=NA, col=redgreen(75), symm=TRUE, trace="none", dendrogram="none", main = paste("Correlation Matrix for time delay at ", sep="")) You'll probably notice that the color bar at the top left isn't the same scale. How do I do this? Thanks, Paul
Benno, That helps but it only makes the color bar symmetrical. I want to be able to compare 2 different heatmaps so that 0.7 (for example) is always the same tone of green and not shifted slightly. Is this possible? Paul On 28 Mar 2011, at 10:42, Benno P?tz wrote:> > On 27.Mrz.2011, at 22:54, Benton, Paul wrote: > >> library(gplots) >> dat<-cor(matrix(rnorm(100, m=10), nrow=10)) >> mat<-cor(matrix(rnorm(100), nrow=10)) >> dev.new() >> heatmap.2(mat, Rowv=NA, Colv=NA, col=redgreen(75), symm=TRUE, trace="none", dendrogram="none", >> main = paste("Correlation Matrix for time delay at ", sep="")) >> dev.new() >> heatmap.2(dat, Rowv=NA, Colv=NA, col=redgreen(75), symm=TRUE, trace="none", dendrogram="none", >> main = paste("Correlation Matrix for time delay at ", sep="")) > In this case adding > > symkey = TRUE > > to the heatmap.2 calls should help > > Benno
On Mon, Mar 28, 2011 at 6:36 PM, Benton, Paul <hpaul.benton08 at imperial.ac.uk> wrote:> Benno, > > That helps but it only makes the color bar symmetrical. I want to be able to compare 2 different heatmaps so that 0.7 (for example) is always the same tone of green and not shifted slightly. Is this possible? > > Paul>From what I can see it is not possible with heatmap.2. If you arelooking for a function that can create a heatmap with a color legend, you can try function image.plot in the package fields, or the function labeledHeatmap in the package WGCNA. Neither of them has the histogram-enhanced color legend, but labeledHeatmap definitely takes an argument zlim which you can set to say c(-1, 1) to obtain a consistent color scale, and the last time I used image.plot (which was quite some time ago), that function also took that argument. See examples listed in help(labeledHeatmap) for a few examples of what it can do. Peter
On Mon, 28 Mar 2011 19:58:40 -0700, Peter Langfelder wrote:> On Mon, Mar 28, 2011 at 6:36 PM, Benton, Paul > <hpaul.benton08 at imperial.ac.uk> wrote: >> Benno, >> >> That helps but it only makes the color bar symmetrical. I want to be >> able to compare 2 different heatmaps so that 0.7 (for example) is >> always the same tone of green and not shifted slightly. Is this >> possible? >> >> Paul > >>From what I can see it is not possible with heatmap.2. If you are > looking for a function that can create a heatmap with a color legend, > you can try function image.plot in the package fields, or the > function > labeledHeatmap in the package WGCNA. Neither of them has the > histogram-enhanced color legend, but labeledHeatmap definitely takes > an argument zlim which you can set to say c(-1, 1) to obtain a > consistent color scale, and the last time I used image.plot (which > was > quite some time ago), that function also took that argument. > > See examples listed in help(labeledHeatmap) for a few examples of > what > it can do. > > Peter > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.Perhaps I misunderstand, but the color scale can be explicitly defined in heatmap.2 using the breaks argument. -- Alex Gutteridge