Jorgy Porgee
2009-Nov-30 19:25 UTC
[R] Is there a way to convert rgb/hex value to a (nearest) color name?
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
Gabor Grothendieck
2009-Nov-30 19:39 UTC
[R] Is there a way to convert rgb/hex value to a (nearest) color name?
Try this:> mycolor <- col2rgb("red"); mycolor[,1] red 255 green 0 blue 0> colors()[sapply(lapply(colors(), col2rgb), identical, mycolor)][1] "red" "red1" On Mon, Nov 30, 2009 at 2:25 PM, Jorgy Porgee <jorgy.porgee@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@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. >[[alternative HTML version deleted]]
Duncan Murdoch
2009-Nov-30 19:39 UTC
[R] Is there a way to convert rgb/hex value to a (nearest) color name?
On 30/11/2009 2:25 PM, Jorgy Porgee 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. > >Here's a recent post on this by Barry Rowlingson: http://finzi.psych.upenn.edu/Rhelp08/2009-October/214886.html Duncan Murdoch
Jorgy Porgee
2009-Nov-30 19:43 UTC
[R] Is there a way to convert rgb/hex value to a (nearest) color name?
Fantastic. Thanks Duncan. Clearly my google key words were the wrong ones, nothing of this sort came up. Hope my title is easier to find somehow.. Regards, George
Henrique Dallazuanna
2009-Nov-30 19:48 UTC
[R] Is there a way to convert rgb/hex value to a (nearest) color name?
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
Seemingly Similar Threads
- How do I ensure that the minimum value is always displayed on a y-axis in a plot?
- Is there a way to round numbers up or down to the nearest "natural looking" number?
- How do I plot a line followed by two forecast points?
- How do I plot: regression line, regression line + s.d, regression line - s.d on the same chart?
- Has any one tested R 2.9.2 on Snow Leopard?