对于在 ggplot2 中排斥标签(例如ggrepel)或标签的阴影文本(例如ggshadowtext和这个答案),有一些很好的解决方案。但是没有什么可以让我们将这两个功能结合起来。
我尝试了这种在稍微不同的位置打印标签多次的技巧,但效果不佳 geom_text_repel
library(ggplot2)
# subset data
d <- diamonds[1:20,]
# make plot
p <- ggplot(d, aes(carat, price)) +
geom_point()
# make halo layers
theta <- seq(pi / 8, 2 * pi, length.out = 16)
xo <- diff(range(d$carat)) / 200
yo <- diff(range(d$price)) / 200
for (i in theta) {
p <- p +
geom_text_repel(data = d,
aes_q(x = bquote(carat + .(cos(i) * xo)),
y = bquote(price + .(sin(i) * yo)),
label …Run Code Online (Sandbox Code Playgroud)