library(ggplot2)
library(ggrepel)
set.seed(1234)
ss <- sample(1:32, 10)
df <- mtcars[ss, ]
ggplot(df, aes(wt, mpg))+ geom_point(col = "red") +
geom_label_repel(aes(label = rownames(df), fill = factor(cyl)), size = 5,
hjust = 1,fontface = 3)
Asked
Active
Viewed 737 times
0

M.R.Wani
- 107
- 1
- 11
-
3Related: [Remove 'a' from legend when using aesthetics and geom_text](https://stackoverflow.com/questions/18337653/remove-a-from-legend-when-using-aesthetics-and-geom-text) – Henrik Nov 17 '18 at 08:58
-
1this may also be useful: https://stackoverflow.com/questions/49989158/how-to-have-a-removed-from-a-ggraph-plot-legend – user20650 Nov 17 '18 at 10:53
-
@Henrik true. Of note though (even if that was not in the OP's question), the solutions offered there do not work to remove the `a` with `ggrepel` (they remove the legend altogether). @user20650's link might offer a way to remove it (works with `ggraph` but I did not test it with `ggrepel`) – prosoitos Nov 17 '18 at 20:23
-
@Henrik, this removes the legend altogether – M.R.Wani Nov 18 '18 at 06:25
1 Answers
5
a
symbolizes the text added by geom_label_repel()
and it matches the font, colour, etc. of your labels.
The picture below shows one of the demo examples of the ggrepel
package shown in the package examples vignette:
You can see the same thing, but with different options passed as arguments to geom_label_repel()
.
If you actually want to remove the letter "a" from the legend you can redefine the legend key as shown here:
# save original legend key for later
oldK <- GeomLabelRepel$draw_key
# define new key without the text label
library(grid)
GeomLabelRepel$draw_key <- function (data, params, size) { draw_key_rect(data) }
# plot
ggplot(df, aes(wt, mpg))+ geom_point(col = "red") +
geom_label_repel(aes(label = rownames(df), fill = factor(cyl)), size = 5,
fontface = 3)
# reset key
GeomLabelRepel$draw_key <- oldK
-
1prosoitos : I hope its okay including the edit to your answer -- if not, please roll back – user20650 Nov 18 '18 at 11:42
-
1Fine by me. The OP was not asking how to remove those `a`, but I am sure that it will be useful, either to them or to others and thus makes for a better answer. Thank you for checking :) – prosoitos Nov 18 '18 at 18:28