Question: Color Triangle and plot
0
gravatar for mchimich
3.2 years ago by
mchimich10
United States
mchimich10 wrote:

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.

enter image description here

Thanks for advance for your help

R • 1.7k views
ADD COMMENTlink modified 3.2 years ago by dariober10k • written 3.2 years ago by mchimich10
1

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:

enter image description here

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.

ADD REPLYlink modified 3.2 years ago • written 3.2 years ago by John12k
1

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...

ADD REPLYlink written 3.2 years ago by Devon Ryan92k

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 -_-;

ADD REPLYlink written 3.2 years ago by John12k
2
gravatar for Devon Ryan
3.2 years ago by
Devon Ryan92k
Freiburg, Germany
Devon Ryan92k wrote:

In R, you want the command rgb(0.2, 0.5, 0.3), which would produce #33804D. Many of the plotting functions can take hex colors like that directly.

ADD COMMENTlink written 3.2 years ago by Devon Ryan92k

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

ADD REPLYlink written 3.2 years ago by mchimich10
2

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.

ADD REPLYlink written 3.2 years ago by Devon Ryan92k
2
gravatar for dariober
3.2 years ago by
dariober10k
WCIP | Glasgow | UK
dariober10k wrote:

Maybe you could play around scale_colour_gradient2 from ggplot2? The vertices of the triangle would be low, mid, high.

Example:

library(ggplot2)
dat<- data.frame(x= 1:20, y= 1:20, z= 1:20)
ggplot(data= dat, aes(x= x, y= y, colour= z)) +
    geom_text(label= dat$z) + 
    scale_colour_gradient2(low = "brown", 
                           mid = "green", 
                           high = "blue", midpoint= median(dat$z))

enter image description here

ADD COMMENTlink written 3.2 years ago by dariober10k
1
gravatar for Manu Prestat
3.2 years ago by
Manu Prestat3.9k
Marseille, France
Manu Prestat3.9k wrote:

What about pixmapRGB() ?

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)
ADD COMMENTlink modified 3.2 years ago • written 3.2 years ago by Manu Prestat3.9k

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 !

ADD REPLYlink written 3.2 years ago by mchimich10

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?

ADD REPLYlink written 3.2 years ago by Manu Prestat3.9k
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: 1805 users visited in the last hour