相关疑难解决方法(0)

如何在ggplot2中组合排斥标签和阴影或光环文本?

对于在 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)

r ggplot2 ggrepel

6
推荐指数
1
解决办法
731
查看次数

标签 统计

ggplot2 ×1

ggrepel ×1

r ×1