[R] col2rgb() function
Nick Wray
n|ckmwr@y @end|ng |rom gm@||@com
Sun Jul 23 20:15:57 CEST 2023
Hello I have a palette vector of colour blind colours (in hexadecimal)
which I’m using for plots, but they are not see-through, and as I wanted to
overlay some histograms I wanted to convert these colours to rgb, when you
can set the opacity.
I have found the function col2rgb(), which works in the sense that it gives
a vector of numbers but these don’t work directly in rgb because they are
too big. If I divide through to make them all less than 1 I don’t get the
corresponding colour-blind hue, but something somewhat off.
Here is the colour-blind palette in a plot:
*cb8<- c("#000000", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2",
"#D55E00", "#CC79A7")*
*plot(0,0,xlim=c(1,8),ylim=c(0,1))*
*points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)*
so if I try to convert the red dot ("#D55E00") (number 7) I get
*col2rgb("#D55E00"*
[,1]
red 213
green 94
blue 0
*points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)*
gives me an error message and although if I divide through
*points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)*
gives me a reddish dot, but not the same as in the colour-blind palette
Somewhat mystified. Can anyone help?? Thanks Nick Wray
[[alternative HTML version deleted]]
More information about the R-help
mailing list