No color observed in Colour Key of HeatMap.2
1
1
Entering edit mode
5.5 years ago
Ming ▴ 110

Dear All,

I am trying to plot a heatmap with the heatmap.2 function, but I am not getting any color on my Color Key.

The following are my code:

col1 <- colorRampPalette(c("green", "black", "red"))(499)

> col_breaks = c(seq(0, 0.002, length = 50),
>                seq(0.0021, 0.004, length = 50),
>                seq(0.0041, 0.006, length = 50),
>                seq(0.0061, 0.008, length = 50),
>                seq(0.0081, 0.01, length = 50),
>                seq(0.011, 0.04, length = 50),
>                seq(0.041, 0.08, length = 50),
>                seq(0.081, 1.2, length = 50),
>                seq(1.21, 1.4, length = 50),
>                seq(1.41, 1.6, length = 50))
heatmap.2(data.matrix(MTB_genus_RA_T), scale = "none", 
          trace = "none", density.info = "density",
          col = col1, breaks = col_breaks,
          Rowv = as.dendrogram(row.clus), Colv = as.dendrogram(col.clus.MTB),
          margins = c(13, 8),
          main = "Heatmap of MTB at the genus level",
          cexRow = 1.1, cexCol = 1.1,
          keysize = 2,
          # key.par=list(mar=c(bottom, left, top, right))
          key.par=list(mar=c(3,5,4,5)))#, lhei = c(0.1, 0.1), lwei = c(0.1, 0.1))
  

I am not getting any color on my color key. Can anyone please help?

enter image description here

Thank you!

R heatmap.2 • 5.4k views
ADD COMMENT
0
Entering edit mode

Perhaps provide an example with a more complete dataset?

Many of your objects (e.g. MTB*) were not included - so we cannot say for sure whether this is a problem that is specifically happening to you or if it is reproducible for others.

ADD REPLY
0
Entering edit mode

Dear @benformatics, what other kind of information will you like?

ADD REPLY
0
Entering edit mode

Why not replace col = col1, breaks = col_breaks, with just col = greenred,? Depending on your purpose, but it seems the values are from 0 to ~1.5 instead of something like -3 to 3 (perhaps using a sequential palette here, for example, brewer.pal(9, "YlGnBu"), would be better).

ADD REPLY
0
Entering edit mode

Dear @SMK, how would you change the code?

ADD REPLY
0
Entering edit mode

Hi Ming,

Something like:

library(gplots)
library(RColorBrewer)

heatmap.2(
  data.matrix(MTB_genus_RA_T),
  scale = "none",
  trace = "none",
  density.info = "density",
  col = greenred,
  main = "Heatmap of MTB at the genus level"
)

heatmap.2(
  data.matrix(MTB_genus_RA_T),
  scale = "none",
  trace = "none",
  density.info = "density",
  col = brewer.pal(9, "YlGnBu"),
  main = "Heatmap of MTB at the genus level"
)
ADD REPLY
1
Entering edit mode
4.2 years ago
morty ▴ 10

Hi, It is likely because of this line: col1 <- colorRampPalette(c("green", "black", "red"))(499)

Do not specify the 499 at the end. This specification of gradation within the colorRampPalette function will mess up the key.

Try again with: col1 <- colorRampPalette(c("green", "black", "red")

ADD COMMENT

Login before adding your answer.

Traffic: 2251 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6