How to plot a colour wheel by using ggplot?
colors, ggplot2, graphics, r
Solution
Was wondering how to do this without `coord_polar()`, since the example from Wickham's book clearly does not. Turns out you can just use `geom_point(...)`.
library(ggplot2)
r <- seq(0,1,length=201)
th <- seq(0,2*pi, length=201)
d <- expand.grid(r=r,th=th)
gg <- with(d,data.frame(d,x=r*sin(th),y=r*cos(th),
z=hcl(h=360*th/(2*pi),c=100*r, l=65)))
ggplot(gg) +
geom_point(aes(x,y, color=z), size=3)+
scale_color_identity()+labs(x="",y="") +
coord_fixed()
This renders in a few seconds. This reference states that the default luminance, l=65.
Problem
I'm reading the book "ggplot2 - Elegant Graphics for Data Analysis" (Wickham, 2009), the section "Scaling" (page 32) says this: Scaling then involves mapping the data values to points in this space. There are many ways to do this, but here since cyl is a categorical variable we map values to evenly spaced hues on the colour wheel, as shown in Figure 3.4. A different mapping is used when the variable is continuous. The result of these conversions is Table 3.4, which contains values that have meaning to the computer. The book doesn't explain in detail how to get this table 3.4, much less figure 3.4. The built-in database is mpg. Anyone has an idea how to get this table and graph? Thanks in advance.