Question: No color observed in Colour Key of HeatMap.2
1
gravatar for Ming
17 months ago by
Ming60
Ming60 wrote:

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!

heatmap.2 R • 1.9k views
ADD COMMENTlink modified 5 weeks ago by morty0 • written 17 months ago by Ming60

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 REPLYlink written 17 months ago by benformatics2.0k

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

ADD REPLYlink written 17 months ago by Ming60

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 REPLYlink modified 17 months ago • written 17 months ago by AK1.9k

Dear @SMK, how would you change the code?

ADD REPLYlink written 17 months ago by Ming60

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 REPLYlink written 17 months ago by AK1.9k
0
gravatar for morty
5 weeks ago by
morty0
morty0 wrote:

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 COMMENTlink written 5 weeks ago by morty0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1655 users visited in the last hour