Remove 'a' from legend when using aesthetics and geom_text
如何从此代码生成的图例中删除字母" a"?如果删除
1 2 3 | ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) + geom_point() + geom_text(aes(label = Species)) |
在
1 2 3 4 | ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species, shape = Species, label = Species)) + geom_point() + geom_text(show.legend = FALSE) |
自变量
前-
像这样的
1 2 3 | ggplot( data=iris, aes(x=Sepal.Length, y=Sepal.Width , colour = Species , shape = Species, label = Species ) , size=20 ) + geom_point()+ geom_text( show_guide = F ) |
我有类似的问题。西蒙的解决方案对我有用,但需要稍加改动。我没有意识到我需要在geom_text的参数中添加" show_guide = F",而不是用它替换现有的参数-这是Simon的解决方案所显示的。对于像我这样的ggplot2菜鸟来说,这并不明显。一个适当的示例将使用OP的代码,并仅添加缺少的参数,如下所示:
1 2 3 | .. geom_text(aes(label=Species), show_guide = F) + .. |
我们可以使用
下面是有关如何使用guide_legend()
的简短示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | library(ggrepel) #> Loading required package: ggplot2 d <- mtcars[c(1:8),] p <- 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" ) # Let's see what the default legend looks like. p |
1 2 3 4 5 6 7 | # Now let's override some of the aesthetics: p + guides( fill = guide_legend( title ="Legend Title", override.aes = aes(label ="") ) ) |
就像尼克说的
以下代码仍会产生错误:
1 | geom_text(aes(x=1,y=2,label="",show_guide=F)) |
而:
1 | geom_text(aes(x=1,y=2,label=""),show_guide=F) |
在aes参数之外消除了图例中的a
您还可以在
因此,而不是
1 2 3 4 5 6 7 8 9 10 11 12 | 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 ="") ) ) |
你可以做,
1 2 3 4 5 6 7 | 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 ) |
我遇到了类似的问题,在试图用
希望对可能正在解决同一问题的任何人都有意义!