如何在ggplot2中翻转geom_curve(箭头)?

3

我似乎无法制作凹箭头。我已经尝试了许多在geom_curve中的angle参数的调整。

可重现示例

library(ggplot2)
library(dplyr)
set.seed(123)
data.frame(x = runif(200)* 1000, y = runif(200)* 1000) %>% 
  ggplot(aes(x, y)) +
  geom_point() + 
  geom_curve(
  aes(x = 200, y = 300, xend = 500, yend = 400),
  arrow = arrow(length = unit(0.03, "npc"), type="closed"), colour = "#EC7014", size = 1.2, angle = 90)

enter image description here

上面的箭头是凸的 - 目标是使箭头呈彩虹形(凹)。我已经改变了角度和起始/结束点,但所有结果都仍然是凸的。

实际例子

这里的箭头指向条形图的粉色部分 - 底部箭头看起来不错,但如果可以使顶部箭头成为凹形,则会更好看。

enter image description here

1个回答

6

我认为你想要的是“曲率”参数。正值具有逆时针旋转的卷曲,而负值则具有顺时针旋转的卷曲。以下是一个示例:

library(ggplot2)

ggplot() + 
  geom_text(aes(x = -5, y = 5, label = "Some text"), size = 10, hjust = 0) +
  geom_rect(aes(xmin = 0, xmax = 5, ymin = 2.5, ymax = 7.5)) +
  geom_curve(aes(x = -2.5, y = 5.5, xend = -1.25, yend = 6),
             arrow = arrow(length = unit(0.03, "npc"), type="closed"), 
             colour = "#EC7014", size = 1.2, curvature = -0.3, angle = 90) +
  geom_curve(aes(x = -2.5, y = 4.5, xend = -1.25, yend = 4),
             arrow = arrow(length = unit(0.03, "npc"), type="closed"), 
             colour = "#EC7014", size = 1.2, curvature = 0.3, angle = 90)

2020年05月09日由 reprex软件包 (v0.3.0)创建


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接