R: how do I draw a line with multiple arrows in it?

前端 未结 5 2039
梦如初夏
梦如初夏 2020-12-04 02:25

I was wondering if anyone could help me plot lines in R with multiple arrows in them, like this:

--->--->--->--->

Thanks in advance!

5条回答
  •  清歌不尽
    2020-12-04 02:59

    Simulair to DWin this is what I came up with:

    arrowLine <- function(x0,y0,x1,y1,nArrow=1,...)
    {
      lines(c(x0,x1),c(y0,y1),...)
      Ax=seq(x0,x1,length=nArrow+1)
        Ay=seq(y0,y1,length=nArrow+1)
      for (i in 1:nArrow)
      {
        arrows(Ax[i],Ay[i],Ax[i+1],Ay[i+1],...)
      }
    }
    

    Basically it overlaps several arrows in a line, but does get the desired result (I assume straigth lines):

    plot(0:1,0:1)
    arrowLine(0,0,1,1,4)
    

    Multiple arrows on a line

    The real tricky part comes to getting the arrow to got o the edge of points instead of the center. Is that needed?

提交回复
热议问题