并不完美,但可能是一个起点。重点是分配initials
and name
配对到无意义的aes
(在这个例子中fill
使用,在其他情况下可能会很棘手),然后覆盖中的键表示scale_*()
.
进行更多调整可能会有所帮助theme
,特别是这占用了大量的屏幕空间:
library(tibble)
library(ggplot2)
library(ggrepel)
df <- tribble(
~x, ~y, ~name, ~initials,
0, 0, "Hadley Wickam", "HW",
0, 1, "Ross Ihaka", "RI",
1, 0, "Robert Gentleman", "RG",
1, 1, "Yihui Xie", "YX"
)
ggplot(df, aes(x, y,
label = initials,
fill = paste(initials, name, sep = '\t-\t'))
) +
geom_point() +
geom_text_repel() +
scale_fill_discrete('Names', guide = guide_legend(override.aes = list(alpha = 0), title.hjust = .5)) +
theme(legend.key = element_blank())
创建于 2018-05-10代表包 http://reprex.tidyverse.org(v0.2.0)。