删除图例 ggplot 2.2 [英] Remove legend ggplot 2.2
本文介绍了删除图例 ggplot 2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图保留一层(平滑)的图例并删除另一层(点)的图例.我尝试使用 guides(colour = FALSE)
和 geom_point(aes(color = vs), show.legend = FALSE)
关闭图例.
I'm trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried shutting off the legends with guides(colour = FALSE)
and geom_point(aes(color = vs), show.legend = FALSE)
.
编辑:由于这个问题及其答案很受欢迎,因此似乎有一个可重现的示例:
Edit: As this question and its answers are popular, a reproducible example seems in order:
library(ggplot2)
ggplot(data = mtcars, aes(x = mpg, y = disp, group = gear)) +
geom_point(aes(color = vs)) +
geom_point(aes(shape = factor(cyl))) +
geom_line(aes(linetype = factor(gear))) +
geom_smooth(aes(fill = factor(gear), color = gear)) +
theme_bw()
推荐答案
from r 食谱,其中 bp 是您的 ggplot:
from r cookbook, where bp is your ggplot:
删除特定美学(填充)的图例:
Remove legend for a particular aesthetic (fill):
bp + guides(fill="none")
也可以在指定比例时进行:
It can also be done when specifying the scale:
bp + scale_fill_discrete(guide="none")
这将删除所有图例:
bp + theme(legend.position="none")
这篇关于删除图例 ggplot 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文