title: Adding arrow segments to a scatter plot in plotly
body: <p>I have <code>XY</code> data I want to plot in a scatter plot using <code>R</code>'s <code>plotly</code> <code>package</code>. 
  For some of the points I have arrows, defined by their X and Y start and end coordinates, which I also want to plot.</p>
  
  <p>Here are the data:</p>
  
  <pre><code>set.seed(1)
  
  df &lt;- data.frame(x=rnorm(100),y=rnorm(100),
                   arrow.x.start=NA,arrow.y.start=NA,
                   arrow.x.end=NA,arrow.y.end=NA)
  
  arrow.idx &lt;- sample(100,20,replace = F)
  
  df$arrow.x.start[arrow.idx] &lt;- df$x[arrow.idx]
  df$arrow.x.end[arrow.idx] &lt;- df$arrow.x.start[arrow.idx]+runif(length(arrow.idx),-0.5,0.5)
  df$arrow.y.start[arrow.idx] &lt;- df$y[arrow.idx]
  df$arrow.y.end[arrow.idx] &lt;- df$arrow.y.start[arrow.idx]+runif(length(arrow.idx),-0.5,0.5)
  </code></pre>
  
  <p>Using <code>ggplot2</code> this is achieved using:</p>
  
  <pre><code>library(ggplot2)
  
  ggplot(df,aes(x=x,y=y))+geom_point()+theme_minimal()+
    geom_segment(aes(x=arrow.x.start,y=arrow.y.start,xend=arrow.x.end,yend=arrow.y.end),arrow=arrow())
  </code></pre>
  
  <p>Which gives:
  <a href="https://i.stack.imgur.com/CqH1c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CqH1c.png" alt="enter image description here"></a></p>
  
  <p>In <code>plotly</code> this will plot the points:</p>
  
  <pre><code>plotly::plot_ly(marker=list(size=5,color="black"),type='scatter',mode="markers",x=df$x,y=df$y,showlegend=F) %&gt;%
    plotly::layout(xaxis=list(title="x",zeroline=F,showticklabels=F,showgrid=F,showgrid=F),yaxis=list(title="y",zeroline=F,showticklabels=F,showgrid=F,showgrid=F))
  </code></pre>
  
  <p>So I'm trying to figure out how to add the arrows.</p>
  
  <p>The <code>add_segments</code> has the <code>x</code>, <code>xend</code>, <code>y</code>, and <code>yend</code> arguments and adding that:</p>
  
  <pre><code>plotly::plot_ly(marker=list(size=5,color="black"),type='scatter',mode="markers",x=df$x,y=df$y,showlegend=F) %&gt;%
    plotly::layout(xaxis=list(title="x",zeroline=F,showticklabels=F,showgrid=F,showgrid=F),yaxis=list(title="y",zeroline=F,showticklabels=F,showgrid=F,showgrid=F)) %&gt;%
    plotly::add_segments(x=df$arrow.x.start,xend=df$arrow.x.end,y=df$arrow.y.start,yend=df$arrow.y.end,line=list(color="blue"))
  </code></pre>
  
  <p>Seems to add a point at the end of the line:</p>
  
  <p><a href="https://i.stack.imgur.com/nnDNt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nnDNt.png" alt="enter image description here"></a></p>
  
  <p>And I couldn't find in its documentation an argument that will add arrow head at the end of the line.</p>
  
  <p>Any idea?</p>