问题描述
我正在尝试从以下图表中删除"n"图例.我猜想它与geom_bar()
的stat
部分有关,但是我不能完全确定它显示的内容,因此不确定如何删除它.我确实想要填充图例,所以show.legends=FALSE
不是正确的选项.抱歉,如果这是重复的,但是之后 很多看起来我找不到答案,在scale_x_x上更改图例并不能解决问题.
I'm trying to remove the 'n' legend from the following plot. I'm guessing it's related to the stat
part of geom_bar()
but am not entirely sure what it is showing and hence am not sure how to remove it. I do want the fill legend so show.legends=FALSE
isn't the right option. Sorry if this is a duplicate but after a lot of looking I can't find the answer, changing the legend on a scale_x_x doesn't cover it.
ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,fill=Species))+
geom_bar(stat="sum")
推荐答案
您可以使用show.legend
参数控制图例,并通过使用命名矢量进行精细控制:
You can control legends with the show.legend
parameter, with fine control by using a named vector:
逻辑.该图层应包括在图例中吗? NA,默认值,包括是否映射了任何美学.永不虚假 包含,并且TRUE始终包含.也可以是命名逻辑 向量以精细地选择要展示的美学效果.
logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.
诀窍是要认识到图例的n部分来自于尺寸美学.
The trick is to recognise that the n part of the legend comes from the size aesthetic.
ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,fill=Species))+
+ geom_bar(stat="sum", show.legend=c(size=FALSE))
这篇关于从ggplot中删除n图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!