gpt4 book ai didi

删除图例 ggplot 2.2

转载 作者:行者123 更新时间:2023-12-03 04:08:17 25 4
gpt4 key购买 nike

我试图保持一层的图例(平滑)并删除另一层的图例(点)。我尝试使用 guides(colour = FALSE)geom_point(aes(color = vs), show.legend = FALSE) 关闭图例。

编辑:由于这个问题及其答案很受欢迎,因此似乎需要一个可重现的示例:

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()

enter image description here

最佳答案

来自 r cookbook ,其中 bp 是你的 ggplot:

删除特定美学的图例(填充):

bp + guides(fill="none")

也可以在指定比例时完成:

bp + scale_fill_discrete(guide="none")

这会删除所有图例:

bp + theme(legend.position="none")

关于删除图例 ggplot 2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35618260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com