Can I use the arrow() function in R to plot a transparent arrow between two points that changes color? For example, an arrow that starts out as red at one point, and gradually changes to blue at the other point (both points are on the same row in a dataframe)? If so, how? And if not, is there another function that can do that in R?
Here is the piece of code I have until now, which draws points (blue and red) and connects the blue points with the red points with transparent blue arrows:
par(xpd=NA, mfrow=c(1,1), mar=c(4.25,3.2,6.20,3.55))
plot(data$x1,data$y1,col="red",pch=20,cex=0.6,xlim=c(xmin,xmax),ylim=c(ymin,ymax),axes=FALSE,ann=FALSE,xaxt='n',yaxt='n')
par(new=T)
plot(data$x2,data$y2,col="blue",pch=20,cex=0.6,xlim=c(xmin,xmax),ylim=c(ymin,ymax),axes=FALSE,ann=FALSE,xaxt='n',yaxt='n')
par(new=T)
plot(grid.picture(NLmap[-1]),xlim=c(xmin,xmax),ylim=c(ymin,ymax),axes=FALSE,ann=FALSE,xaxt='n',yaxt='n')
par(new=T)
points(data$x1,data$y1,col="red",pch=20,cex=0.25)
par(new=T)
points(data$x2,data$y2,col="blue",pch=20,cex=0.25)
par(new=T)
arrows(data$x1,data$y1, data$x2, data$y2, length = 0.05, angle = 30,
code = 2, col = "#9AC0CD40", lty = par("lty"), lwd = par("lwd"))
Hope this helps!
First of all, I should mention that my answer is directly derived from the information provided in the comments and the answer by DWin. I had never seen those functions before, so I thought I would give them a shot.
I ended up creating a little function that works like
arrowsexcept a colour scale is added. I think this is essentially what you want.The arrow head will have a colour that matches the ‘end’ colour given in
color.scale.arrow.