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

From: Earl F. Glynn <>
Date: Mon, 07 Jul 2008 16:30:57 -0500

"hadley wickham" <> wrote in message
> On Mon, Jul 7, 2008 at 1:05 PM, Earl F. Glynn <>
> wrote:
>> "hadley wickham" <> wrote in message >>

> Well, I do have fixup = FALSE, which the documentation indicates
> should return NA if the chroma exceeds the actual upper bound.

You did specify fixup in the hcl data.frame but I'm not sure how that info was used when you called the hcl function since fixup is a parameter to the hcl function.

Compare the two plots from below. When you get the NAs you want, the odd colors go away, but I'm not sure you'll like the results:

# I dropped fixup from the data.frame (and used variable names that "Code Complete 2" might approve):

hcl.grid <- expand.grid(hue = seq(0, 360, by = 2),

                        chroma = 70,
                        luminance = seq(0, 100, by= 2))

hcl.grid <- transform(hcl.grid,
  angle = hue * pi / 180,
  radius = luminance / 100

hcl.grid <- transform(hcl.grid,
  x = radius * sin(angle),
  y = radius * cos(angle)

# What you have
hcl.grid$colour1 <- hcl(hcl.grid$hue, hcl.grid$chroma, hcl.grid$luminance,


with(hcl.grid, plot(x, y, col=colour1, pch=20))

# What you intended?
hcl.grid$colour2 <- hcl(hcl.grid$hue, hcl.grid$chroma, hcl.grid$luminance,


with(hcl.grid, plot(x, y, col=colour2, pch=20))


Earl F Glynn
Stowers Institute for Medical Research mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 07 Jul 2008 - 21:38:27 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 Mon 07 Jul 2008 - 22:31:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive