我正在阅读《 ggplot2-用于数据分析的优雅图形》(Wickham,2009年)一书,“缩放”部分(第32页)说:
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.
本书没有详细解释如何获得该表3.4,更不用说图3.4了。内置数据库为 mpg 。任何人都有一个想法如何获取此表和图形?
提前致谢。
最佳答案
想知道如何在没有coord_polar()
的情况下执行此操作,因为Wickham的书中的示例显然没有。原来,您可以只使用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 reference指出默认亮度l = 65。
关于r - 如何使用ggplot绘制色轮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21490210/