Create bidirectional arrow as annotation in plotly R

Considering the mtcars dataset, I'm trying to plot a scatter plot.

ggplot(mtcars,           
       aes(x = hp,   
           y = wt)) + 
  geom_point() +
  stat_smooth()

I know how to create an arrow to label data values using annotations in R but how can I create a bidirectional arrow as annotation? I'm wondering if below figure could be created in plotly R using annotations

Hi @April,

My solution to the arrows is using 2x geom_segment () . Probably there are nicer ways, but it works.

ggplot(mtcars, aes(x = hp, y = wt)) + geom_point() + stat_smooth() + geom_segment(aes(x = 100, y=5, xend=200, yend=5), lineend = 'square', linejoin = 'round', size = 2, arrow = arrow(length=unit(0.5, "cm" ))) + geom_segment(aes(x = 100, y=5, xend=50, yend=5), lineend = 'square', linejoin = 'round', size = 2, arrow = arrow(length=unit(0.5, "cm" )))

Hope this gets you going.

JW

Hi @Jwvz001,

Thank you for your response!

Hi @April, you're welcome. Just out of curiousity, did you accomplish where you're after? Or did you find a nicer solution?

JW

Hi @Jwvz001, I did accomplish my task with the help of your code snippet. I couldn't find any other solution.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.