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)
答案 0 :(得分:4)
a
象征着geom_label_repel()
添加的文本,它与标签的字体,颜色等匹配。
下面的图片显示了包示例插图中显示的ggrepel
包的演示示例之一:
您可以看到相同的内容,但是将不同的选项作为参数传递给geom_label_repel()
。
如果您实际上想从图例中删除字母“ a”,则可以重新定义图例键,如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