Re: [R] Selecting complementary colours

2007-05-22 Thread John Fox
Dear Thomas,

This seems simpler than the solution that I used, so I'll give it a
try.

Thanks,
 John

On Tue, 22 May 2007 09:01:01 -0700 (PDT)
 Thomas Lumley <[EMAIL PROTECTED]> wrote:
> On Mon, 21 May 2007, John Fox wrote:
> >
> > In retrospect, I didn't specify the problem clearly: What I want to
> be able
> > to do is to place text on a background of arbitrary (but known RGB)
> colour
> > so that the text is legible. I guess that this is better described
> as a
> > "contrasting" than a "complementary" colour.
> 
> Since luminance contrasts are necessary and sufficient for readable
> text, you could use white for dark colors and black for light colors.
> 
> Luminance is roughly proportional to  0.2*(R^2.4)+0.6*(G^2.4),
> suggesting something like
> 
> lightdark<-function (color)
> {
>  rgb <- col2rgb(color)/255
>  L <- c(0.2, 0.6, 0) %*% rgb
>  ifelse(L >= 0.2, "#60", "#A0")
> }
> 
> This uses a pale yellow for dark backgrounds and a dark blue for
> light backgrounds, and it seems to work reasonably well.
> 
>   -thomas


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-22 Thread Earl F. Glynn
"John Fox" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> The object is to get contrasting colours, so that
> when one is plotted over the other, the two will be readily 
> distinguishable.

A simple approach to contrast is to compute a mean intensity by taking the 
mean of the three  RGB components (should be 0..255) and then going with 
either "black" or "white" -- whichever one  is "farthest" away.

Look at the Color Chart with contrasting numbers
http://research.stowers-institute.org/efg/R/Color/Chart/index.htm
or
http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.pdf

efg

Earl F. Glynn
Stowers Institute for Medical Research

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-22 Thread Thomas Lumley
On Mon, 21 May 2007, John Fox wrote:
>
> In retrospect, I didn't specify the problem clearly: What I want to be able
> to do is to place text on a background of arbitrary (but known RGB) colour
> so that the text is legible. I guess that this is better described as a
> "contrasting" than a "complementary" colour.

Since luminance contrasts are necessary and sufficient for readable text, 
you could use white for dark colors and black for light colors.

Luminance is roughly proportional to  0.2*(R^2.4)+0.6*(G^2.4), suggesting 
something like

lightdark<-function (color)
{
 rgb <- col2rgb(color)/255
 L <- c(0.2, 0.6, 0) %*% rgb
 ifelse(L >= 0.2, "#60", "#A0")
}

This uses a pale yellow for dark backgrounds and a dark blue for light 
backgrounds, and it seems to work reasonably well.

-thomas

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-22 Thread John Fox
Dear Chuck,

This solution works reasonably well for me. Although it occasionally
produces an error, I'm able to trap that.

Thank you -- and to everyone else who responded.

John


John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: Charles C. Berry [mailto:[EMAIL PROTECTED] 
> Sent: Monday, May 21, 2007 8:49 PM
> To: John Fox
> Cc: 'Deepayan Sarkar'; r-help@stat.math.ethz.ch
> Subject: Re: [R] Selecting complementary colours
> 
> On Mon, 21 May 2007, John Fox wrote:
> 
> > Dear Deepayan,
> >
> > I actually thought of the equivalent of this approach, but 
> it doesn't 
> > do quite what I want.
> >
> > In retrospect, I didn't specify the problem clearly: What I 
> want to be 
> > able to do is to place text on a background of arbitrary (but known 
> > RGB) colour so that the text is legible. I guess that this 
> is better 
> > described as a "contrasting" than a "complementary" colour.
> 
> John,
> 
> There may be no unique solution. (For gray, for example.)
> 
> I am not sure (in terms of color theory) that maximizing in 
> rgb space really is the right thing to do, but perhaps this 
> will help you:
> 
> > cval <- function(x,y) -sum((x-y)^2)
> > contrasting <- function(x) 
> > 
> optim(runif(3,0,255),cval,lower=0,upper=255,method="L-BFGS-B",y=x)$par
> > do.call(rgb,as.list(contrasting(col2rgb("gray"))/255))
> [1] "#00"
> > do.call(rgb,as.list(contrasting(col2rgb("gray"))/255))
> [1] "#FF"
> > do.call(rgb,as.list(contrasting(col2rgb("pink"))/255))
> [1] "#00FF00"
> 
> Regards,
> 
> Chuck
> 
> >
> 
> >
> > Your solution, for example breaks down for grays:
> >
> >> mycol <- "#88"
> >> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
> > [1] "#77"
> >
> > Thank you for the suggestion.
> >
> > John
> >
> > 
> > John Fox, Professor
> > Department of Sociology
> > McMaster University
> > Hamilton, Ontario
> > Canada L8S 4M4
> > 905-525-9140x23604
> > http://socserv.mcmaster.ca/jfox
> > 
> >
> >> -Original Message-
> >> From: [EMAIL PROTECTED] 
> >> [mailto:[EMAIL PROTECTED] On Behalf Of Deepayan 
> >> Sarkar
> >> Sent: Monday, May 21, 2007 6:45 PM
> >> To: John Fox
> >> Cc: r-help@stat.math.ethz.ch
> >> Subject: Re: [R] Selecting complementary colours
> >>
> >> On 5/21/07, John Fox <[EMAIL PROTECTED]> wrote:
> >>> Dear r-helpers,
> >>>
> >>> I wonder whether, given the "#rrggbb" representation of a colour, 
> >>> there is a simple way to select the complementary colour,
> >> also expressed as a "#rrggbb"
> >>> string.
> >>>
> >>> Any suggestions would be appreciated.
> >>
> >> You want rgb2col. The following should work for any standard color
> >> specification:
> >>
> >>> mycol = "royalblue"
> >>> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
> >> [1] "#BE961E"
> >>
> >> -Deepayan
> >>
> >> __
> >> R-help@stat.math.ethz.ch 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.
> >>
> >
> > __
> > R-help@stat.math.ethz.ch 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.
> >
> 
> Charles C. Berry(858) 534-2098
>   Dept of 
> Family/Preventive Medicine
> E mailto:[EMAIL PROTECTED] UC San Diego
> http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 
> 92093-0901
> 
> 
>

__
R-help@stat.math.ethz.ch 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.


[R] Selecting complementary colours

2007-05-21 Thread Ken Knoblauch
Hi John and all,

I'm getting into this late and I think that most of the bases have been
touched.  But just to dot some "eyes",...

Some years ago, I proposed some general rules of thumb that should help
in generating optimally contrasting text for nearly anyone, that have been
distilled into a few simple rules at this website.

http://www.lighthouse.org/accessibility/effective-color-contrast/

A basic part of the guidelines include maximizing luminance contrast.

Mike Kubovy, is absolutely correct that iso- or equiluminant  colors would be
difficult to detect because the chromatic systems in the eye are spatially
low pass, though chromatic aberration would tend to work against this
for large text a little bit by adding some luminance transients at the edges.
If your viewer happens to be a garden variety dichromat (protanope or
deuteranope), then you have to worry about choosing colors along one
of his confusion lines.  For example, for a deuteranope, there exists
equiluminant magenta and cyan that appear gray, so these would
generate an invisible contrast for the observer (maybe some outline
would be vaguely visible because of chromatic aberrations in the eye).
It's a little different for the protanope because he (and it is mostly he's)
has a luminosity loss, so his confusion line is not in an equiluminant plane.
Early stages of some prevalent eye diseases can produce a different
type of chromatic loss, in which violet vs yellow-green contrasts are
difficult to detect.

Colorimetrically, complementaries are defined as pairs of lights whose
additive
mixture matches a reference white.  So, according to the definition,
either gray is its own complementary, or a null light would also qualify.
To arbitrarily generate true complementaries would require the lights to be
specified in an additive system.   So, if you wanted
colorimetrically precise complementaries, you would need to have
your screen/printer calibrated.

HTH,

Ken



*
Hi All,

Complementary colors will not insure legibility. If the text and the
background are equiluminant, visibility will be severely impaired.

On May 21, 2007, at 8:22 PM, John Fox wrote:

> Dear Achim,
>
> As I mentioned in my response to Deepayan's suggestion, I didn't
> specify the
> original problem clearly: The object is to get contrasting colours,
> so that
> when one is plotted over the other, the two will be readily
> distinguishable.
> Your suggestions don't do this for neutral colours:
>
>> x <- "#88"
>> y_hcl <- as(hex2RGB(x), "polarLUV")
>> y_hcl at coords[1, "H"] <- y_hcl at coords[1, "H"] + 180
>> hex(y_hcl)
> [1] "#88"
>
>> y_hsv <- as(hex2RGB(x), "HSV")
>> y_hsv at coords[1, "H"] <- y_hsv at coords[1, "H"] + 180
>> hex(y_hsv)
> [1] "#88"
>
> Thank you for trying to help.
>
> John
>
> 
> John Fox, Professor
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
> 
>
>> -Original Message-
>> From: Achim Zeileis [mailto:Achim.Zeileis at wu-wien.ac.at]
>> Sent: Monday, May 21, 2007 7:07 PM
>> To: John Fox
>> Cc: r-help at stat.math.ethz.ch
>> Subject: Re: [R] Selecting complementary colours
>>
>> On Mon, 21 May 2007, John Fox wrote:
>>
>>> Dear r-helpers,
>>>
>>> I wonder whether, given the "#rrggbb" representation of a colour,
>>> there is a simple way to select the complementary colour,
>> also expressed as a "#rrggbb"
>>> string.
>>
>> Is the complementary color uniquely defined? My understanding
>> is that you can take opposite colors on a color wheel, but
>> there are of course various color wheels available. With
>> "colorspace" you can experiment with this,
>> e.g.:
>>   x <- "#81A9D0"
>>   y_hcl <- as(hex2RGB(x), "polarLUV")
>>   y_hcl at coords[1, "H"] <- y_hcl at coords[1, "H"] + 180
>>   y_hcl <- hex(y_hcl)
>> which is a bit more balanced than
>>   y_hsv <- as(hex2RGB(x), "HSV")
>>   y_hsv at coords[1, "H"] <- y_hsv at coords[1, "H"] + 180
>>   y_hsv <- hex(y_hsv)
>>
>> hth,
>> Z
>>
>>
>>
>
> __
> R-help at stat.math.ethz.ch 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, 

Re: [R] Selecting complementary colours

2007-05-21 Thread Charles C. Berry
On Mon, 21 May 2007, John Fox wrote:

> Dear Deepayan,
>
> I actually thought of the equivalent of this approach, but it doesn't do
> quite what I want.
>
> In retrospect, I didn't specify the problem clearly: What I want to be able
> to do is to place text on a background of arbitrary (but known RGB) colour
> so that the text is legible. I guess that this is better described as a
> "contrasting" than a "complementary" colour.

John,

There may be no unique solution. (For gray, for example.)

I am not sure (in terms of color theory) that maximizing in rgb space 
really is the right thing to do, but perhaps this will help you:

> cval <- function(x,y) -sum((x-y)^2)
> contrasting <- function(x) 
> optim(runif(3,0,255),cval,lower=0,upper=255,method="L-BFGS-B",y=x)$par
> do.call(rgb,as.list(contrasting(col2rgb("gray"))/255))
[1] "#00"
> do.call(rgb,as.list(contrasting(col2rgb("gray"))/255))
[1] "#FF"
> do.call(rgb,as.list(contrasting(col2rgb("pink"))/255))
[1] "#00FF00"

Regards,

Chuck

>

>
> Your solution, for example breaks down for grays:
>
>> mycol <- "#88"
>> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
> [1] "#77"
>
> Thank you for the suggestion.
>
> John
>
> 
> John Fox, Professor
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
> --------
>
>> -Original Message-
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Deepayan Sarkar
>> Sent: Monday, May 21, 2007 6:45 PM
>> To: John Fox
>> Cc: r-help@stat.math.ethz.ch
>> Subject: Re: [R] Selecting complementary colours
>>
>> On 5/21/07, John Fox <[EMAIL PROTECTED]> wrote:
>>> Dear r-helpers,
>>>
>>> I wonder whether, given the "#rrggbb" representation of a colour,
>>> there is a simple way to select the complementary colour,
>> also expressed as a "#rrggbb"
>>> string.
>>>
>>> Any suggestions would be appreciated.
>>
>> You want rgb2col. The following should work for any standard color
>> specification:
>>
>>> mycol = "royalblue"
>>> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
>> [1] "#BE961E"
>>
>> -Deepayan
>>
>> __
>> R-help@stat.math.ethz.ch 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.
>>
>
> __
> R-help@stat.math.ethz.ch 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.
>

Charles C. Berry(858) 534-2098
  Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]   UC San Diego
http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0901

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-21 Thread Michael Kubovy
Hi All,

Complementary colors will not insure legibility. If the text and the  
background are equiluminant, visibility will be severely impaired.

On May 21, 2007, at 8:22 PM, John Fox wrote:

> Dear Achim,
>
> As I mentioned in my response to Deepayan's suggestion, I didn't  
> specify the
> original problem clearly: The object is to get contrasting colours,  
> so that
> when one is plotted over the other, the two will be readily  
> distinguishable.
> Your suggestions don't do this for neutral colours:
>
>> x <- "#88"
>> y_hcl <- as(hex2RGB(x), "polarLUV")
>> [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
>> hex(y_hcl)
> [1] "#88"
>
>> y_hsv <- as(hex2RGB(x), "HSV")
>> [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
>> hex(y_hsv)
> [1] "#88"
>
> Thank you for trying to help.
>
> John
>
> 
> John Fox, Professor
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
> ----
>
>> -Original Message-
>> From: Achim Zeileis [mailto:[EMAIL PROTECTED]
>> Sent: Monday, May 21, 2007 7:07 PM
>> To: John Fox
>> Cc: r-help@stat.math.ethz.ch
>> Subject: Re: [R] Selecting complementary colours
>>
>> On Mon, 21 May 2007, John Fox wrote:
>>
>>> Dear r-helpers,
>>>
>>> I wonder whether, given the "#rrggbb" representation of a colour,
>>> there is a simple way to select the complementary colour,
>> also expressed as a "#rrggbb"
>>> string.
>>
>> Is the complementary color uniquely defined? My understanding
>> is that you can take opposite colors on a color wheel, but
>> there are of course various color wheels available. With
>> "colorspace" you can experiment with this,
>> e.g.:
>>   x <- "#81A9D0"
>>   y_hcl <- as(hex2RGB(x), "polarLUV")
>>   [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
>>   y_hcl <- hex(y_hcl)
>> which is a bit more balanced than
>>   y_hsv <- as(hex2RGB(x), "HSV")
>>   [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
>>   y_hsv <- hex(y_hsv)
>>
>> hth,
>> Z
>>
>>
>>
>
> __
> R-help@stat.math.ethz.ch 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.

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-21 Thread John Fox
Dear Achim,

As I mentioned in my response to Deepayan's suggestion, I didn't specify the
original problem clearly: The object is to get contrasting colours, so that
when one is plotted over the other, the two will be readily distinguishable.
Your suggestions don't do this for neutral colours:

> x <- "#88"
> y_hcl <- as(hex2RGB(x), "polarLUV")
> [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
> hex(y_hcl)
[1] "#88"
 
> y_hsv <- as(hex2RGB(x), "HSV")
> [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
> hex(y_hsv)
[1] "#88"

Thank you for trying to help.

John


John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: Achim Zeileis [mailto:[EMAIL PROTECTED] 
> Sent: Monday, May 21, 2007 7:07 PM
> To: John Fox
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] Selecting complementary colours
> 
> On Mon, 21 May 2007, John Fox wrote:
> 
> > Dear r-helpers,
> >
> > I wonder whether, given the "#rrggbb" representation of a colour, 
> > there is a simple way to select the complementary colour, 
> also expressed as a "#rrggbb"
> > string.
> 
> Is the complementary color uniquely defined? My understanding 
> is that you can take opposite colors on a color wheel, but 
> there are of course various color wheels available. With 
> "colorspace" you can experiment with this,
> e.g.:
>   x <- "#81A9D0"
>   y_hcl <- as(hex2RGB(x), "polarLUV")
>   [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
>   y_hcl <- hex(y_hcl)
> which is a bit more balanced than
>   y_hsv <- as(hex2RGB(x), "HSV")
>   [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
>   y_hsv <- hex(y_hsv)
> 
> hth,
> Z
> 
> 
>

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-21 Thread John Fox
Dear Deepayan,

I actually thought of the equivalent of this approach, but it doesn't do
quite what I want.

In retrospect, I didn't specify the problem clearly: What I want to be able
to do is to place text on a background of arbitrary (but known RGB) colour
so that the text is legible. I guess that this is better described as a
"contrasting" than a "complementary" colour.

Your solution, for example breaks down for grays:

> mycol <- "#88"
> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
[1] "#77"

Thank you for the suggestion.

John


John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Deepayan Sarkar
> Sent: Monday, May 21, 2007 6:45 PM
> To: John Fox
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] Selecting complementary colours
> 
> On 5/21/07, John Fox <[EMAIL PROTECTED]> wrote:
> > Dear r-helpers,
> >
> > I wonder whether, given the "#rrggbb" representation of a colour, 
> > there is a simple way to select the complementary colour, 
> also expressed as a "#rrggbb"
> > string.
> >
> > Any suggestions would be appreciated.
> 
> You want rgb2col. The following should work for any standard color
> specification:
> 
> > mycol = "royalblue"
> > do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
> [1] "#BE961E"
> 
> -Deepayan
> 
> __
> R-help@stat.math.ethz.ch 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.
>

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-21 Thread Achim Zeileis
On Mon, 21 May 2007, John Fox wrote:

> Dear r-helpers,
>
> I wonder whether, given the "#rrggbb" representation of a colour, there is a
> simple way to select the complementary colour, also expressed as a "#rrggbb"
> string.

Is the complementary color uniquely defined? My understanding is that you
can take opposite colors on a color wheel, but there are of course various
color wheels available. With "colorspace" you can experiment with this,
e.g.:
  x <- "#81A9D0"
  y_hcl <- as(hex2RGB(x), "polarLUV")
  [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
  y_hcl <- hex(y_hcl)
which is a bit more balanced than
  y_hsv <- as(hex2RGB(x), "HSV")
  [EMAIL PROTECTED], "H"] <- [EMAIL PROTECTED], "H"] + 180
  y_hsv <- hex(y_hsv)

hth,
Z

__
R-help@stat.math.ethz.ch 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.


Re: [R] Selecting complementary colours

2007-05-21 Thread Deepayan Sarkar
On 5/21/07, John Fox <[EMAIL PROTECTED]> wrote:
> Dear r-helpers,
>
> I wonder whether, given the "#rrggbb" representation of a colour, there is a
> simple way to select the complementary colour, also expressed as a "#rrggbb"
> string.
>
> Any suggestions would be appreciated.

You want rgb2col. The following should work for any standard color
specification:

> mycol = "royalblue"
> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
[1] "#BE961E"

-Deepayan

__
R-help@stat.math.ethz.ch 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.


[R] Selecting complementary colours

2007-05-21 Thread John Fox
Dear r-helpers,

I wonder whether, given the "#rrggbb" representation of a colour, there is a
simple way to select the complementary colour, also expressed as a "#rrggbb"
string.

Any suggestions would be appreciated.

John


John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

__
R-help@stat.math.ethz.ch 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.