问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/53348955/why-does-text-appear-in-the-legend