I simply want to draw multiple arrows on a scatterplot using ggplot2. In this (dummy) example, an arrow is drawn but it moves as i is incremented and only one arrow is drawn. Why does that happen?
library(ggplot2)
a <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
b <- data.frame(x1=c(2,3),y1=c(10,10),x2=c(3,4),y2=c(15,15))
for (i in 1:nrow(b)) {
a <- a + geom_segment(arrow=arrow(),
mapping = aes(x=b[i,1],y=b[i,2],xend=b[i,3],yend=b[i,4]))
plot(a)
}
Thanks.
See Question&Answers more detail:os