ggplot2:每个方面单独的色标

发布于 2024-10-02 22:10:06 字数 459 浏览 0 评论 0原文

直觉上我正在寻找类似的东西: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宫墨修音 2024-10-09 22:10:06

当您按因子着色时,我不确定这是一个可用的选项。然而,生成单个图的快速方法如下:

d_ply(mpg, .(manufacturer), function(df) {
jpeg(paste(df$manufacturer[[1]], ".jpeg", sep=""))
plots <- ggplot(df, aes(year, displ, color=factor(model))) + geom_jitter()
print(plots)
dev.off()
})

相关答案:
多面 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:

d_ply(mpg, .(manufacturer), function(df) {
jpeg(paste(df$manufacturer[[1]], ".jpeg", sep=""))
plots <- ggplot(df, aes(year, displ, color=factor(model))) + geom_jitter()
print(plots)
dev.off()
})

Related Answers:
Different legends and fill colours for facetted ggplot?

无语# 2024-10-09 22:10:06

我认为您只是想按类别着色,每个制造商都会生产多个模型,每个模型每个类别只有一个或两个:

p <- ggplot(mpg, aes(year, displ, color=class)) + facet_wrap(~ manufacturer)
p + geom_jitter()

alt text

I think you simply want to color by class, where each manufacturer makes several models, each only one or two per class:

p <- ggplot(mpg, aes(year, displ, color=class)) + facet_wrap(~ manufacturer)
p + geom_jitter()

alt text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文