1

I have multiple heat maps similar to the following:

X <- matrix(nrow=3, ncol=3)
X[1,] <- c(0.3, 0.4, 0.45)
X[2,] <- c(0.3, 0.7, 0.65)
X[3,] <- c(0.3, 0.4, 0.45)
colnames(X)<-c(1.5, 3, 4)
rownames(X)<-c(1.5, 3, 4)
library(gplots)

heatmap.2( X, Rowv=NA, Colv=NA, col=rev(heat.colors(256)), 
           sepcolor="black", trace="none",dendrogram="none" )

Now, in order to make multiple plots of this kind look more similar, how can I get the upper left histogram to always go between 0 and 1?


Based on yuk's answer I made this version:

X <- matrix(nrow=3, ncol=3)
X[1,] <- c(0.3, 0.4, 0.45)
X[2,] <- c(0.3, 0.7, 0.65)
X[3,] <- c(0.3, 0.4, 0.45)
colnames(X)<-c(1.5, 3, 4)
rownames(X)<-c(1.5, 3, 4)
library(gplots)

colors <- rev(heat.colors(256))

colbr <- c(seq(0, 1, len=length(colors)+1))
heatmap.2(X, scale="none", col=colors, breaks=colbr,
          key=T, symkey=F, density.info="histogram", trace="none", Rowv=NA, Colv=NA, 
          sepcolor="black", dendrogram="none" )

Now the color scale goes between 0 and 1 bit the histogram does still not.enter image description here

jonalv
  • 5,706
  • 9
  • 45
  • 64
  • If you fix the color scale, why you want the histogram to change? To do this you have to scale your data, so 0.3 becomes 0, and 0.7 becomes 1. Is it what you want? – yuk Aug 29 '13 at 21:36
  • 1
    No. I have multiple graphs like this and I would like the histograms to cover the same range in all of them. As things are now, the value corresponding a histogram-staple which is for example situated in the middle of two of these histogram plots will not be the same but depend on what is the max value and min value in their respective heat maps. I want to make it as easy as possible to compare multiple graphs of this kind. But fixing the color scale is definitely a step in the right direction, although something I had not included in this minimal working example. – jonalv Aug 30 '13 at 07:49
  • So if you could manually set the axis then you could determine the max of all of your data sets and set your axis to be the same. Would this accomplish what you want? – ptpaterson Sep 03 '13 at 23:17
  • Yes, that is a great way of explaining what I want. – jonalv Sep 04 '13 at 11:19

1 Answers1

0

I think the best way is to set color breaks.

Here is what i usually do (x is the matrix for heatmap):

n.col=16 # number of colors
cm = redblue(n.col) # red-white-blue colormap
mmx = min(abs(min(x)),abs(max(x))) # find min value, or you can set to a number
colbr <- c(seq(-mmx/2,mmx/2, len=length(cm)+1)) # vector of symmetric breaks
heatmap.2(x, scale="none", col=cm, breaks=colbr,
          key=T, symkey=F, density.info="histogram", trace="none")
yuk
  • 19,098
  • 13
  • 68
  • 99