删除ggplot中的图例标题

编程入门 行业动态 更新时间:2024-10-27 13:35:23
本文介绍了删除ggplot中的图例标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试删除 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 =)主题(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中的图例标题

本文发布于:2023-07-19 17:04:23,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图例   标题   ggplot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!