Convert color hex code to color names
To add slightly to that:
What you want to do is write a function that returns the named color that has the smallest difference to your input hex-triplet. But note that color difference is a large topic. Assuming you want to minimize *perceptual* differences, you want to calculate your differences in Lab color space. The function convertColor() has the option to convert hex to Lab. Example:
convertColor(t(col2rgb("thistle")), from="sRGB", to="Lab", scale.in=255)
Within Lab space, you can take the Euclidian distance.
That all said, I can't imagine why one would want to do this in the first place - color triplets are much more convenient than label strings :-)
B.
On Apr 13, 2015, at 11:45 AM, Thierry Onkelinx <thierry.onkelinx at inbo.be> wrote:
A combination of rgb(), col2rgb() and colors() can gives hex values for the named colors. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey 2015-04-13 17:28 GMT+02:00 Alejo C.S. <alej.c.s at gmail.com>:
Hi all, I want to convert the output of:
rainbow(6)
[1] "#FF0000FF" "#FFFF00FF" "#00FF00FF" "#00FFFFFF" "#0000FFFF"
"#FF00FFFF"
To a vector of color names. Any tip?
Thanks in advance
C.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.