I was wondering if anyone could help me plot lines in R with multiple arrows in them, like this:
--->--->--->--->
Thanks in advance!
There's a sneaky way to do this without having to plot a bunch of line segments or arrows.
Start with x
and y
data as above:
plot(x, y, t='l')
Then calculate the local slopes from x[1]
, y[1]
to x[2]
, y[2]
and so on, using some canned routine. Convert the slopes to angles in degrees, and then (calling the vector of slopes angslopes
)
text(x, y, labels=">", srt=angslopes) # throws error
Sorry, that won't work because, so far as I can tell, srt
must be a single value. So:
diflen <- length(x)-1
sapply(1:diflen, function(xind) text(x[xind+1], y[xind+1], labels='>', cex=2.5, srt=angslopes[xind]))
There may well be a much easier way to do this in the lattice package.
This approach has the cosmetic advantage of allowing you to specify the arrowhead size via par(cex)
as well as the color - which could be different from the line color, or even varying along the curve.