[R] Is there a way to convert rgb/hex value to a (nearest) color name?

Henrique Dallazuanna wwwhsd at gmail.com
Mon Nov 30 20:48:45 CET 2009


You can try something about like this:

yourColor <-  c(250,235,215)
colors()[which.min(colSums(col2rgb(colors()) - yourColor
)[colSums(col2rgb(colors()) - yourColor) >= 0])]

On Mon, Nov 30, 2009 at 5:25 PM, Jorgy Porgee <jorgy.porgee at gmail.com> wrote:
> Hi all, I'm trying to convert a series of rgb codes into a color name.
> What is my easiest option? So far I'm stuck with just converting to
> hex using rgb() and I know R knows a number of colours() but a mapping
> of the two has failed me.
>
> Any help in this regard will be highly appreciated.
>
> Regards,
>
> George
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list