【发布时间】:2018-12-13 12:34:57
【问题描述】:
我希望更改一些(但不是全部)标签的颜色,以便它们在填充图中突出。我使用以下方法实现了这一点:
df <- data.frame("x"=1:10, "y"=1:10, "dir"=rep(c("a", "b"), 5))
library(ggplot2)
library(ggrepel)
ggplot(data=df, aes(x, y, color=dir)) +
geom_point(show.legend=TRUE) +
geom_text_repel(data=df[1:5, ],
aes(x=x, y=y,
color=factor(df$dir[1:5], labels=c("text a", "text b")),
label=dir),
size=2.5, force=15, show.legend=FALSE) +
scale_colour_manual(values=c("salmon", "black", "salmon", "darkturquoise"))
如何在图例中隐藏标签配色方案的同时执行此操作(即在下图中去掉文本 a 和文本 b)? show.legend=FALSE 似乎不起作用,我想保留点图例。
在这个例子中,我使用的是geom_text_repel,但我想geom_text 也是一样的。
谢谢!
【问题讨论】: