I am trying to replicate figure 6.11 from Hadley Wickham's ggplot2 book, which plots R colors in Luv space; the colors of points represent themselves, and no legend is necessary.
Here are two attempts:
library(colorspace)
myColors <- data.frame("L"=runif(10000, 0,100),"a"=runif(10000, -100, 100),"b"=runif(10000, -100, 100))
myColors <- within(myColors, Luv <- hex(LUV(L, a, b)))
myColors <- na.omit(myColors)
g <- ggplot(myColors, aes(a, b, color=Luv), size=2)
g + geom_point() + ggtitle ("mycolors")
Second attempt:
other <- data.frame("L"=runif(10000),"a"=runif(10000),"b"=runif(10000))
other <- within(other, Luv <- hex(LUV(L, a, b)))
other <- na.omit(other)
g <- ggplot(other, aes(a, b, color=Luv), size=2)
g + geom_point() + ggtitle("other")
There are a couple of obvious problems:
- These graphs don't look anything like the figure. Any suggestions on
the code needed?
- The first attempt generates a lot of NA fields in the Luv
column (only ~3100 named colors out of 10,000 runs, versus ~9950 in
the second run). If L is supposed to be between 0-100 and u and v
between -100 and 100, why do I have so many NAs in the first run? I have tried rounding, it doesn't help.
- Why do I have a legend?
Many thanks.