r - 如何使用ggplot绘制色轮?

标签 r graphics colors ggplot2

我正在阅读《 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/

相关文章:

python - 使用python OpenCV将单一值颜色转换为LAB

r - 处理存储在列表中的数据框

r - 如何将分钟数据转换为小时平均数据

java - 如何在 Java 中处理自定义的、可选择的线路类

linux - 条形图和其他图形未在终端中显示(Debian 和 R)

r - ggplot 中的十六进制颜色未按预期着色

r - 使用格子个性化 R 上显示的 X 轴值

r - R中的 "diagonal"矩阵平方

Space Invaders 的 C++ 图形更新

java - 从 Android 颜色转换为 HTML 颜色