Re: [R] Selecting complementary colours

From: John Fox <jfox_at_mcmaster.ca>
Date: Mon, 21 May 2007 20:18:45 -0400


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 <- "#888888"
> do.call(rgb, as.list(1 - col2rgb(mycol) / 255))
[1] "#777777"

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: r-help-bounces_at_stat.math.ethz.ch
> [mailto:r-help-bounces_at_stat.math.ethz.ch] On Behalf Of Deepayan Sarkar
> Sent: Monday, May 21, 2007 6:45 PM
> To: John Fox
> Cc: r-help_at_stat.math.ethz.ch
> Subject: Re: [R] Selecting complementary colours
>
> On 5/21/07, John Fox <jfox_at_mcmaster.ca> 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_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, minimal, self-contained, reproducible code.
>



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, minimal, self-contained, reproducible code. Received on Tue 22 May 2007 - 00:24:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 May 2007 - 16:31:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.