Dear biostars community !
After spending few days looking on the net I finally decide to post my question here.
I wanted to create a heatmap but using three color depending on the ratio between three values. This is an example :
A (0.2), B (0.5) and C (0.3)
for example the A is blue, the B is red and the C is green (see the triangle). for that particular point which is the resulting color (it must be more blue > > green > red). I really don't know where to start and if there is an automatic way to do it in R for example.
From a purley data-viz point of view, this is probably not a good idea. True colour is not a three dimensional thing, it's only 1 dimension, you just happen to have 3 receptors in your face. This would be OK if it wasn't for the fact that the receptors overlap in what they pick up, so they are non-independant:
There is a second dimension your eyes can pick up, light intensity, although since the eyes have a non-linear response to the amount of light coming in and the amount of light perceived, depending on colour, this makes using light intensity quite difficult. For sure, if you use RGB, this non-linear correction will not be done. The HCL colour palette however is designed to make this correction, and it's built into R. (http://hclwizard.org/why-hcl/) (https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/hcl.html)
But even HCL provides you with 3 dials to fiddle with: Hue, Chroma and Luminosity. chroma and hue are not perceived independently, so set the chroma, then use only H and L, or set the hue and use only C and L.
If you really have three dimensions that are totally separate, you're better off using 3D space. If you were plotting these three colours in 2D space before, consider swapping everything around. Plot a scatter based on the data you're using for colour, then colour the scatter in using HCL with the data you previously used for X and Y.
There's always a bit too much made out of the overlap in photoreceptor sensitivity. The brain is able to handle that just fine. The bigger issue is red-green color blind individuals...
Dear Ryan, thanks so much this is exactly what I was looking for ! However I don't know whether we can change the primary color code from red, green and blue to other color combination ?
Anyway thanks again that help a lot
You're only going to get the normal combinations that exist in color specifications, such as rgb() and hsv(). Any other color only defined as a combination of these scores anyway.
library(pixmap)
A <- runif(n = 400, min = 0, max = 1)
B <- runif(n = 400, min = 0, max = 1)
C <- runif(n = 400, min = 0, max = 1)
z <- pixmapRGB(c(B,C,A), 20, 20, bbox=c(-1,-1,1,1))
plot(z)
Thanks Manu for your reply. sorry but I'm not sure to understand what is going on here. I try your code and I obtain a nice plot with many different colors but can't understand what does it mean. can you please explicit your answer ? Many thanks again !
Hi,
well, here I've just randomly generated 400 values between 0 and 1 (such as your triangle example) for A, B and C. Instead, I believe you would make a matrix with B,C,A as columns (to be in the same order as RGB in your example), and your measurements as rows.
And then you plot with pixmapRGB() the 400 triplets values converted to RGB colors in, arbitrary, 20 col and 20 rows. The idea is I guess that you would have several conditions (e.g. 20) and several (e.g. 20) {A,B,C} triplets (samples?) / condition which you would like to plot as colors, if not, you would not have thought about a heatmap, right?
From a purley data-viz point of view, this is probably not a good idea. True colour is not a three dimensional thing, it's only 1 dimension, you just happen to have 3 receptors in your face. This would be OK if it wasn't for the fact that the receptors overlap in what they pick up, so they are non-independant:
There is a second dimension your eyes can pick up, light intensity, although since the eyes have a non-linear response to the amount of light coming in and the amount of light perceived, depending on colour, this makes using light intensity quite difficult. For sure, if you use RGB, this non-linear correction will not be done. The HCL colour palette however is designed to make this correction, and it's built into R. (http://hclwizard.org/why-hcl/) (https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/hcl.html)
But even HCL provides you with 3 dials to fiddle with: Hue, Chroma and Luminosity. chroma and hue are not perceived independently, so set the chroma, then use only H and L, or set the hue and use only C and L.
If you really have three dimensions that are totally separate, you're better off using 3D space. If you were plotting these three colours in 2D space before, consider swapping everything around. Plot a scatter based on the data you're using for colour, then colour the scatter in using HCL with the data you previously used for X and Y.
There's always a bit too much made out of the overlap in photoreceptor sensitivity. The brain is able to handle that just fine. The bigger issue is red-green color blind individuals...
Oh yeah, I must admit, i'm pretty bad at remembering to take that into consideration. All the more reason to avoid colour if possible -_-;