ggplot2:每个方面单独的色标
直觉上我正在寻找类似的东西: facet_(scales="free_color")
我做了类似的事情
p <- ggplot(mpg, aes(year, displ, color=model)) + facet_wrap(~manufacturer)
p + geom_jitter()
那就是:绘制属于不同物种的个体(model
)的二维测量值(manufacturer
) 由物种组成,通过颜色表示个体。 问题是所有个体都共享相同的色标 - 因此一个面上的点具有非常相似的颜色。
将群体美学与 geom_line 一起使用可以解决问题,但线与点讲述的故事不同。
另一个明显的解决方案是放弃分面并为每个子集绘制单独的图。 (如果这是唯一的解决方案:是否有任何快速、智能或经过验证的方法可以做到这一点?)
Intuitively I'm looking for something like: facet_(scales="free_color")
I do something like
p <- ggplot(mpg, aes(year, displ, color=model)) + facet_wrap(~manufacturer)
p + geom_jitter()
That is: plot 2d measurements from individuals(model
) belonging to different species(manufacturer
) faceted by a species, indicating the individual by color.
The problem is that all individuals share the same color scale - so that the points in a facet have very similar colors.
Using the group aesthetic with geom_line would solve the problem, but lines tell different story than dots.
Another obvious solution would be to drop the faceting and draw a separate plot for each subset. (If this should be the only solution: are there any quick, smart or proven ways to do that?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您按因子着色时,我不确定这是一个可用的选项。然而,生成单个图的快速方法如下:
相关答案:
多面 ggplot 的不同图例和填充颜色?
I'm not sure that this is an available option when you're colouring by a factor. However, a quick way to produce the individual plots would be something like this:
Related Answers:
Different legends and fill colours for facetted ggplot?
我认为您只是想按类别着色,每个制造商都会生产多个模型,每个模型每个类别只有一个或两个:
I think you simply want to color by class, where each manufacturer makes several models, each only one or two per class: