我正在尝试删除传奇的标题ggplot2:
df <- data.frame(
  g = rep(letters[1:2], 5),
  x = rnorm(10),
  y = rnorm(10)
)
library(ggplot2)
ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") + 
  theme(legend.position="bottom")

我已经看到了这个问题,似乎没有任何解决方案对我有用.大多数人都提出了关于如何opts弃用和使用的错误theme.我也尝试了各种版本theme(legend.title=NULL),theme(legend.title=""),theme(legend.title=element_blank)等典型的错误信息是:
'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in version 0.9.1)
'theme_blank' is deprecated. Use 'element_blank' instead. (Deprecated; last used in version 0.9.1)
ggplot2自从0.9.3版本发布以来我第一次使用,我发现很难导航一些变化......
jub*_*uba 178
你几乎就在那里:只需添加 theme(legend.title=element_blank())
ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") + 
  theme(legend.position="bottom") +
  theme(legend.title=element_blank())
Cookbook for R上的这个页面提供了有关如何自定义图例的大量详细信息.
这也有效,并演示了如何更改图例标题:
ggplot(df, aes(x, y, colour=g)) +
  geom_line(stat="identity") + 
  theme(legend.position="bottom") +
  scale_color_discrete(name="")
另一个选项使用labs并将颜色设置为NULL.
ggplot(df, aes(x, y, colour = g)) +
  geom_line(stat = "identity") +
  theme(legend.position = "bottom") +
  labs(colour = NULL)