How to flip geom_curve (arrow) in ggplot2?

Viewed 759

I can't seem to make arrows concave. I have tried many adjustments to the angle argument in geom_curve

Reproducible example

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

The arrow above is convex - the goal is to make the arrow the shape of a rainbow (concave). I have altered angle and start/end points but all the resulting arrows are still convex

Practical Example

Here the arrows point to the pink parts of the bars - the bottom arrow looks fine, but the top one would look better if it could be made concave

enter image description here

1 Answers

I think you want the curvature parameter. Positive values have a counter-clockwise curl, and negative values a clockwise curl. Here's a reprex:

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)

Created on 2020-05-09 by the reprex package (v0.3.0)

Related