R 拆下';a';使用美学和几何图形文本时从图例开始
如何从该代码生成的图例中删除字母“a”?如果删除R 拆下';a';使用美学和几何图形文本时从图例开始,r,ggplot2,aesthetics,R,Ggplot2,Aesthetics,如何从该代码生成的图例中删除字母“a”?如果删除geom_文本,则图例中将不会显示“a”字母。不过,我想保留geom_text ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) + geom_point() + geom_text(aes(label = Species)) 在geom_text中设置show.legend=FALSE: ggp
geom_文本
,则图例中将不会显示“a”字母。不过,我想保留geom_text
ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) +
geom_point() +
geom_text(aes(label = Species))
在
geom_text
中设置show.legend=FALSE
:
ggplot(data = iris,
aes(x = Sepal.Length, y = Sepal.Width, colour = Species,
shape = Species, label = Species)) +
geom_point() +
geom_text(show.legend = FALSE)
参数show\u guide
在ggplot2.0.0
()中将名称更改为show.legend
ggplot2.0.0之前的版本 用
show\u guide=FALSE
像这样
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width , colour = Species,
shape = Species, label = Species ), size = 20) +
geom_point() +
geom_text(show_guide = FALSE)
我有一个问题。西蒙的解决方案对我有效,但需要稍微改变一下。我没有意识到我需要在geom_text的参数中添加“show_guide=F”,而不是替换现有的参数,这正是Simon的解决方案所显示的。对于像我这样的傻瓜来说,这并不明显。一个合适的例子应该使用OP的代码,只添加缺少的参数,如下所示:
..
geom_text(aes(label=Species), show_guide = F) +
..
就像尼克说的
以下代码仍将产生错误:
geom_text(aes(x=1,y=2,label="",show_guide=F))
鉴于:
geom_text(aes(x=1,y=2,label=""),show_guide=F)
在aes参数之外,消除了图例上的a
我们可以使用
guide\u图例(override.aes=aes(…)
隐藏图例中的“a”
下面是一个简短的示例,说明如何使用
库(ggrepel)
#>加载所需包:ggplot2
d您也可以在geom\u label\u repel()
的参数中使用show.legend=FALSE
删除图例中的“a”。
因此,与其
ggplot(d, aes(wt, mpg)) +
geom_point() +
theme_classic(base_size = 18) +
geom_label_repel(
aes(label = rownames(d), fill = factor(cyl)),
size = 5, color = "white"
)+ guides(
fill = guide_legend(
title = "Legend Title",
override.aes = aes(label = "")
)
)
你可以
ggplot(d, aes(wt, mpg)) +
geom_point() +
theme_classic(base_size = 18) +
geom_label_repel(
aes(label = rownames(d), fill = factor(cyl)),
size = 5, color = "white",
show.legend = FALSE )
我有一个类似的问题,在我试图用geom\u text\u repel
标记的不同颜色点后面出现了一个“a”。要删除“a”,使其只显示点而不显示后面的“a”,我必须在geom\u text\u repel
中添加show.legend=FALSE
作为参数
希望这对任何可能为同样的问题而工作的人都有意义 将ggplot2
3.2.1中的show.legend
设置为FALSE
,将完全删除该图例!有没有办法将“a”自定义为其他类似“r”的东西?我认为这是一个比公认的解决方案更好的解决方案,因为它允许从图例中明确删除“a”字母,而如果需要,其他美学可以保持不变。