如何用 ggplot 抑制图例

Bre*_*nan 5 r ggplot2

我有以下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*')'))
Run Code Online (Sandbox Code Playgroud)

我尝试了几种方法来抑制传说,但似乎无法弄清楚,而且我尝试过的任何方法都没有做任何事情。有没有人遇到过这个问题/知道如何做到这一点?我已将其包含+ theme(legend.position = "none")在上面的代码中,因为这是我的最后一次尝试,我也尝试过legend = FALSE,但也没有任何结果。

Wil*_*iam 7

您尝试过其中一些吗?

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

plot + guides(colour=FALSE)
Run Code Online (Sandbox Code Playgroud)

或者

删除 geom_line() 内的图例:

geom_line(aes(...), show.legend = FALSE))
Run Code Online (Sandbox Code Playgroud)