[R] Selecting complementary colours

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Tue May 22 01:06:30 CEST 2007

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,
  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)


More information about the R-help mailing list