This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Making a heat map more clear

Hi,

I have plotted log normalised data in a heatmap as this picture but how I can make the dots more clrear and darker please?

heatmap.2(d, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), scale="row", density.info="none", trace="none",col=colfunc(20))
heatmap r

2 answers

Just scale it yourself and set breaks accordingly. Then, it will [usually] look better.

Pick a color scheme and set breaks

require("RColorBrewer")
myCol <- colorRampPalette(c("dodgerblue", "black", "yellow"))(100)
myBreaks <- seq(-2, 2, length.out=101)

Transform your data to the Z-scale (row-wise)

heat <- t(scale(t(sc_DEGG)))

Plot the heatmap, specify your custom breaks and colour scheme, and switch further scaling (by heatmap.2) off

require("gplots")

heatmap.2(heat,
  Rowv=as.dendrogram(hr),
  Colv=as.dendrogram(hc),
  col=myCol,
  breaks=myBreaks,
  main="Title",
  key=T,
  keysize=1.0,
  scale="none",
  density.info="none",
  reorderfun=function(d,w) reorder(d, w, agglo.FUN=mean),
  trace="none",
  cexRow=0.2,
  cexCol=0.8,
  distfun=function(x) dist(x, method="euclidean"),
  hclustfun=function(x) hclust(x, method="ward.D2"))

Excuse me,

saying:

Error in if (key) { : argument is not interpretable as logical
In addition: Warning message:
In if (key) { :
  the condition has length > 1 and only the first element will be used

Sorry, you are using Ward clustering but in

hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="complete")


hc <- hclust(as.dist(1-cor(y, method="spearman")), method="complete")

you also using

Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc)

Is this a double clustering?

Sorry, yes, you are supplying your own dendrograms. Regardng the 'key', you can just remove those, as they were just the default values. You just need to do:

heatmap.2(heat, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), col=myCol, breaks=myBreaks, main="Title", scale="none", density.info="none", reorderfun=function(d,w) reorder(d, w, agglo.FUN=mean), trace="none", cexRow=0.8, cexCol=0.8)

By the way, in your original heatmap, the breaks were way to high with regard to colour and the distribution of values (-10, 0, +10). By scaling the data yourself and setting the breaks lower, you are virtually guaranteed to bring out more colour into the heatmap. Hope that this makes sense. Please feel free to change the breaks to -1/+1, -3+3, -5+5, etc.

seems like it's mostly a problem of resolution, increasing the size of the image (and therefore of each dot) may help already.

Perhaps, Kamil's tips on how to map the color to quantiles rather than absolute numbers may also be of help.

That is a great link ... thanks a lot

Thanks a lot, always helpful you are

Log in to answer this question.