0

I am using heatmap.2 for heatmapping my data. My data consists of matrices with numeric values between 70 and 100 (representing similarities between samples), and i want to define clearcut barriers with no gradient colors.

library(gplots)
library(RColorBrewer)
#defining my colors
mypal <- brewer.pal(n = 6, name = "Spectral")
#defining the breaks as per ?heatmap.2
breaks <- c(0,75.0,78.5,82.0,86.5,94.5,100)

heatmap.2(m,
              Rowv=TRUE,
              Colv="Rowv",
              density.info="histogram", 
              trace="none",     
              labCol=FALSE,
              labRow=FALSE,
              key.title=NA,
              key.ylab=NA,
              keysize=2,
              col=mypal,      
              breaks=breaks,   
              dendrogram="row")

I did that with three different input matrices, and each time one of the breaks is omitted. I cannot figure out why. Here is an image:

http://s29.postimg.org/j3561w3uv/Keys.png

I define 6 colors for six classes, but one is ignored. The first three breaks are seemingly of the same size (which they shouldnt be). Also, the histogram doesnt follow the color breaks in the key chart, and the x-axis scaling is always different.

Where do i fail?

Thank you!

Here is a random submatrix, obtained from my data:

structure(c(100, 96.7, 95.8, 94.8, 95.9, 94.3, 93.6, 94, 93.1, 
91.9, 93.7, 91.8, 92, 91, 96.7, 100, 97.3, 95.6, 97.7, 95, 93.4, 
94.2, 93.3, 92.5, 93.2, 91.3, 92.3, 91.3, 95.8, 97.3, 100, 95.2, 
97, 94, 92, 92.6, 91.7, 90.8, 93, 91.2, 91.8, 91.3, 94.8, 95.6, 
95.2, 100, 95.9, 95, 91.5, 92.2, 91.8, 90.9, 93.9, 92.3, 93.4, 
92.7, 95.9, 97.7, 97, 95.9, 100, 95.4, 92.6, 93.7, 92.1, 92.1, 
92.8, 91.1, 91.8, 91.4, 94.3, 95, 94, 95, 95.4, 100, 91.4, 92.2, 
92.1, 91.3, 92.9, 91.2, 92.1, 91.5, 93.6, 93.4, 92, 91.5, 92.6, 
91.4, 100, 97.1, 95.8, 94.5, 90.8, 89.3, 90.5, 90.7, 94, 94.2, 
92.6, 92.2, 93.7, 92.2, 97.1, 100, 96, 94.3, 91.9, 90.6, 91.7, 
92.2, 93.1, 93.3, 91.7, 91.8, 92.1, 92.1, 95.8, 96, 100, 94.8, 
91.5, 91.1, 90.7, 90.9, 91.9, 92.5, 90.8, 90.9, 92.1, 91.3, 94.5, 
94.3, 94.8, 100, 89.4, 88.7, 89.9, 90.3, 93.7, 93.2, 93, 93.9, 
92.8, 92.9, 90.8, 91.9, 91.5, 89.4, 100, 95, 94, 93.4, 91.8, 
91.3, 91.2, 92.3, 91.1, 91.2, 89.3, 90.6, 91.1, 88.7, 95, 100, 
92.2, 92.6, 92, 92.3, 91.8, 93.4, 91.8, 92.1, 90.5, 91.7, 90.7, 
89.9, 94, 92.2, 100, 93.2, 91, 91.3, 91.3, 92.7, 91.4, 91.5, 
90.7, 92.2, 90.9, 90.3, 93.4, 92.6, 93.2, 100), .Dim = c(14L, 
14L), .Dimnames = list(c("A", "B", "C", "D", "E", "F", "G", "H", 
"I", "J", "K", "L", "M", "N"), (c("A", "B", "C", "D", "E", "F", "G", "H", 
"I", "J", "K", "L", "M", "N")))

Judging from this, it seems like the key is only representing a break, if according data is present above a certain abundance treshold. I tried it with new, arbitrary breaks:

breaks2 <- c(0,89.0,91.5,93.0,95.5,97.5,100)
png("test.png", height=1000, width=1000, res = 300, pointsize = 8)
heatmap.2(mat_data_test,
          main = "SG3",
          Rowv=TRUE,
          Colv="Rowv",
          density.info="density", 
          trace="none",     
          labCol=FALSE,
          labRow=FALSE,
          key.title=NA,
          key.ylab=NA,
          keysize=2,
          col=mypal,      
          breaks=breaks2,   
          dendrogram="row")
dev.off()

and again, several breaks are ignored. Thanks for your help!

nouse
  • 3,315
  • 2
  • 29
  • 56
  • You have not defined `m` within this script – maloneypatr Sep 08 '14 at 15:12
  • m is my input matrix. It is a square matrix with numeric values ranging between 70 and 100. I am sorry. – nouse Sep 08 '14 at 15:34
  • You can use `dput` to print out your matrix, and copy it in your question. That way you will have provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and you will have a lot more chance of someone helping you. – ROLO Sep 08 '14 at 16:55
  • Done. As my input matrices are huge, i opted for random submatrices instead. – nouse Sep 09 '14 at 14:32

0 Answers0