请忽略整个图形上的随机点-这只是一个快速可重现的示例,以显示我的意思:
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, fill = Species)) +
geom_violin(alpha = 0.5) +
stat_summary(aes(shape="mean",group=1),fun = "mean",
size = 2, geom = "point", color = "black") +
stat_summary(aes(shape = "median", group = 2), fun = "median",
size = 2, geom = "point", color = "red") +
labs(x = "Sepal Length", y = "Sepal Width",
shape = "Shape", colour = "Species") +
theme_classic()
我如何能:
一种)。更改图例,以便每个分类变量的框中间没有红点?b)。更改“形状”图例的颜色,以便“均值”为黑色,“中位数”为红色?
我已经用Google搜索了一个多小时,但找不到答案,因此非常感谢您的帮助。谢谢!
override.aes
图例指南有一个论点,您可以使用它来显式设置键的外观。
library(ggplot2)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, fill = Species)) +
geom_violin(alpha = 0.5) +
stat_summary(aes(shape="mean",group=1),fun = "mean",
size = 2, geom = "point", color = "black") +
stat_summary(aes(shape = "median", group = 2), fun = "median",
size = 2, geom = "point", color = "red") +
labs(x = "Sepal Length", y = "Sepal Width",
shape = "Shape", colour = "Species") +
guides(
shape = guide_legend(override.aes = list(colour = c("black", "red"))),
fill = guide_legend(override.aes = list(shape = NA))
) +
theme_classic()
#> Warning: position_dodge requires non-overlapping x intervals
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句