Skip to content
Prev 349937 / 398513 Next

Convert color hex code to color names

About 1-2 years ago, I have improved the 

      demo("colors", package = "grDevices")

demo in R.... with inspiration from Marius Hofert.

The demo now features a  nearRcolor() function 
that was written for somewhat like that purpose.

 ##' Find close R colors() to a given color {original by Marius Hofert)
 ##' using Euclidean norm in (HSV / RGB / ...) color space
 nearRcolor <- function(rgb, cSpace = c("hsv", "rgb255", "Luv", "Lab"),
                        dist = switch(cSpace, "hsv" = 0.10, "rgb255" = 30,
                        "Luv" = 15, "Lab" = 12))
 .............
 .............

It allows to use different color spaces and a default set of
cutoffs, for defining what  "near" means.

I had thought at the time to make a regular function out of
it, but then did not follow up on myself :-)

Martin Maechler,
ETH Zurich and R core team