如何使用 ggplot 抑制图例

问题描述 投票:0回答:1

我有以下

ggplot
代码:

ggplot(Wheat_by_yearContinent, aes(x = Year, y = avgWheatYield, color = ContinentName)) + 
  theme(legend.position = "none") + 
  geom_line(size = 1) + 
  expand_limits(y = 0) + 
  ggtitle("Wheat") + 
  ylab(bquote('Average Yield ( '*'ton'~ ha^-1*')'))

我尝试了几种方法来抑制图例,但似乎无法弄清楚,而且我尝试过的任何方法都没有做任何事情。有没有人遇到过这个问题/知道如何做到这一点?我在上面的代码中包含了

+ theme(legend.position = "none")
,因为这是我的最后一次尝试,我也尝试了
legend = FALSE
,但也没有任何结果。

r ggplot2
1个回答
8
投票

您尝试过其中一些吗?

从特定的美学中删除图例:

plot + guides(colour=FALSE)

编辑 请注意,自

<scale>
版本 3.3.4 起,
guides()
colour=
参数(
fill=
"none"
等)采用
FALSE
而不是
ggplot2

删除 geom_line() 中的图例:

geom_line(aes(...), show.legend = FALSE))
© www.soinside.com 2019 - 2024. All rights reserved.