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

Earl F. Glynn efg at stowers-institute.org
Mon Jul 7 23:30:57 CEST 2008


"hadley wickham" <h.wickham at gmail.com> wrote in message 
news:f8e6ff050807071247nca6f950we6e4b95556862f20 at mail.gmail.com...
> On Mon, Jul 7, 2008 at 1:05 PM, Earl F. Glynn <efg at stowers-institute.org> 
> wrote:
>> "hadley wickham" <h.wickham at gmail.com> wrote in message
>> news:f8e6ff050807070906y272bf4b9u7a356a5da0850653 at mail.gmail.com...

> 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,
                        fixup=TRUE)
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,
                        fixup=FALSE)
with(hcl.grid, plot(x, y, col=colour2, pch=20))


efg

Earl F Glynn
Bioinformatics
Stowers Institute for Medical Research



More information about the R-help mailing list