小编gen*_*ana的帖子

通过 geom_label_repel 向 ggplot 添加一个带有填充头部的箭头

我想使用该geom_label_repel函数向 ggplot 对象添加一个带有填充头部的箭头。我以为我可以使用:arrow.fill = 'black'就像我对 所做的那样geom_segment,但它在geom_label_repel. 这是获得填充箭头的另一种方法吗?

我使用 的原因geom_label_repel是它是我设法在标签边界处开始箭头的唯一方法。如果可以通过其他方式找到此坐标,我可以使用geom_segment代替。

library(tidyverse)
library(ggrepel)

dmax <- iris %>%
  filter(Sepal.Length == max(Sepal.Length))

ggplot(data = iris, aes(x=Sepal.Width, y=Sepal.Length)) +
  geom_point() +
  geom_label_repel(data=dmax, aes(label = 'max'), 
                   box.padding = unit(.25, 'lines'), 
                   point.padding = unit(1.5, 'lines'), 
                   arrow = arrow(length = unit(0.25, 'cm'), type = 'closed')) +
  geom_segment(aes(x=3, xend=max(Sepal.Width), y=0, yend=max(Sepal.Width)), 
               arrow=arrow(length = unit(0.25, 'cm'), type = 'closed'), 
               arrow.fill = 'black')
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggrepel

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

标签 统计

ggplot2 ×1

ggrepel ×1

r ×1