0
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)

In the legend, why does 'a' appear alongside, 4,6,8?enter image description here

M.R.Wani
  • 107
  • 1
  • 11
  • 3
    Related: [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
  • 1
    this 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 Answers1

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:

enter image description here

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
user20650
  • 24,654
  • 5
  • 56
  • 91
prosoitos
  • 6,679
  • 5
  • 27
  • 41
  • 1
    prosoitos : I hope its okay including the edit to your answer -- if not, please roll back – user20650 Nov 18 '18 at 11:42
  • 1
    Fine 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