[R] Drawing a colour wheel - bug in hcl?

hadley wickham h.wickham at gmail.com
Mon Jul 7 18:06:38 CEST 2008


Hi All,

I'm trying trying to draw a colour wheel (a slice of hcl space) in R.
Running the code below doesn't give me what I expect - there's some
oddly bright colours of the wrong hue around c(0, 0) and I see three
coloured circles (a small magenta, a medium sized yellow and a large
cyan).  Am I doing something wrong or is there a bug in the hcl code?

(Also any suggestions for generating a more evenly spaced grid of
colours would be greatly appreciated)

Regards,

Hadley

hcl <- expand.grid(h = seq(0, 360, by = 2), c = 70, l = seq(0, 100, by
= 2), fixup=FALSE)
hcl <- transform(hcl,
  angle = h * pi / 180,
  radius = l / 100
)
hcl <- transform(hcl,
  x = radius * sin(angle),
  y = radius * cos(angle)
)
hcl$colour <- hcl(hcl$h, hcl$c, hcl$l)

with(hcl, plot(x, y, col=colour, pch=20))

-- 
http://had.co.nz/



More information about the R-help mailing list