我尝试删除 ggplot2 中的图例标题:
<$ (10),$ b $ = rnorm(10),y = rnorm(10) 库(ggplot2) ggplot(df,aes(x,y,color = g))+ geom_line(stat =identity)+ 主题(legend.position =bottom)
我见过这个问题,并没有任何解决方案似乎为我工作。大多数关于如何 opts 不推荐使用的错误以及使用主题代替的错误。我也尝试了各种版本的主题(legend.title = NULL), theme(legend.title =)$ c $典型的错误信息是:
主题(legend.title = element_blank) 'opts'已被弃用。改为使用主题。 (已弃用;上次在版本0.9.1中使用)'theme_blank'已弃用。改为使用'element_blank'。 (已弃用;上次在0.9.1版本中使用)我正在使用 ggplot2 自0.9.3版本发布以来第一次发现,并且我发现很难浏览一些更改...
解决方案您几乎在那里:只需添加主题(legend.title = element_blank())
ggplot(df,aes(x,y,color = g))+ geom_line(stat =identity)+ theme .position =bottom)+ theme(legend.title = element_blank())这本Cookbook for R 页面提供了大量关于如何定制传奇的细节。
I'm trying to remove the title of a legend in 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")I've seen this question and none of the solutions there seem to work for me. Most give an error about how opts is deprecated and to use theme instead. I've also tried various versions of theme(legend.title=NULL), theme(legend.title=""), theme(legend.title=element_blank), etc. Typical error messages are:
'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)I'm using ggplot2 for the first time since version 0.9.3 was released and I'm finding it difficult to navigate some of the changes...
解决方案You were almost there : just add 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())This page on Cookbook for R gives plenty of details on how to customize legends.
更多推荐
删除ggplot中的图例标题
发布评论