color gradient for heatmap2
2
0
Entering edit mode
12 months ago
jtehmsen ▴ 20

Hello,

I'd like to create a continuous gradient of warm colors (e.g., yellow-orange-red) from the values 4-9 using heatmap2. Can anyone please suggest code to replace "col=bluered(100)" in the code below?

> heatmap.2(as.matrix(dataSub), Colv=FALSE, Rowv=FALSE, trace="none", dendrogram="none", scale="none", density.info="none", breaks = seq(4,9, length.out = 101), col=bluered(100), cexCol=0.75,margins=c(15,24))

I've tried colorRampPalette but can't seem to get what I'm looking for.

Thanks very much for any help.

heatmap heatmap2 color gradient • 462 views
ADD COMMENT
0
Entering edit mode
12 months ago

You likely need to scale your data, or set the breaks to match the data distribution that you currently have.

If you simply set scale = 'row', for all intents and purposes, that may improve the heatmap from an aesthetics standpoint. This will result in heamap.2() Z-scaling your data per row. However, your current chosen values for breaks seems strange to me.

Another way to do this is to scale your input data via:

heatmap.2(
  t(scale(t(dataSub))),
  ...)

This has the exact same effect as setting scale = 'row'.

Take a quick look at my example here, ignoring the zFPKM part, though: Heatmap based with FPKM values

Kevin

ADD COMMENT
1
Entering edit mode

Hi Kevin, thanks for your help and quick response, looking at your example helped solve the problem. I guess I was trying to use one less color in the gradient than needed for the number of breaks. Using your example I changed it to "col=colorRampPalette(c("yellow", "orange", "red"))(100)" and this seems to have resolved the issue. Thank you for your time and help, stay safe and well.

ADD REPLY
0
Entering edit mode
12 months ago
Tao ▴ 420

I think you can try to remove col=bluered(100), because in default, they use yellow-red schema. P.S. You can create a vector of n contiguous colors using the functions rainbow(n), heat.colors(n), terrain.colors(n), topo.colors(n), and cm.colors(n).

ADD COMMENT
0
Entering edit mode

Thank you Tao, I'll explore this too.

ADD REPLY

Login before adding your answer.

Traffic: 1471 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