如何使用ggplot绘制色轮? [英] How to plot a colour wheel by using ggplot?

查看:718
本文介绍了如何使用ggplot绘制色轮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读这本书ggplot2 - 用于数据分析的优雅图形(Wickham,2009),缩放一节(第32页)说:


然后,缩放涉及将数据值映射到此空间中的点。有很多方法可以做到这一点,但在这里,由于 cyl 是一个分类
变量,我们将值映射到色轮上均匀间隔的色调, as
如图3.4所示。当变量是
连续时,使用不同的映射。这些转换的结果是表3.4,其中
包含对计算机有意义的值。






本书没有详细解释如何获取此表3.4 ,更少的数字3.4。内置数据库为 mpg 。任何人都有一个想法如何得到这个表和图形?

想知道如何在没有 coord_polar()的情况下这样做

/ code>,因为Wickham的书的例子显然不是。原来你可以使用 geom_point(...)

 库(ggplot2)
r< - seq(0,1,length = 201)
th< - seq(0,2 * pi,length = 201)
d& grid(d,x = r * sin(th),y = r * cos(th),
z(r = r,th = th) = 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()



这将在几秒钟后呈现。 此参考资料说明默认亮度,l = 65。


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.

解决方案

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.

这篇关于如何使用ggplot绘制色轮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆