我正在尝试移除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)
自从0.9.3版本发布以来,我第一次使用ggplot2
,发现有些更改很难搞懂......
labs()
来完成这个操作:在生成以上图表的代码中添加一行labs(colour = "")
。 - Dennis