I would like to create a plot with segements or arrows.
Let's say I have this toy example
temp <- data.frame(posi=c(1,2,3,3,2,1,5), from=c("A", "B", "C", "D", "D", "B", "A"),
to=c( "C", "D", "D", "C", "A", "A", "B"))
posi from to
1 A C
2 B D
3 C D
3 D C
2 D A
1 B A
5 A B
And I want to plot segments or arrows from the points defined by "from" and its starting position to the points defined by "to" and position+1.
I got to create the plot with ggplot
ggplot() + geom_point(data=temp, aes(x=posi, y=from, size=10),show.legend = FALSE) +
geom_point(data=temp, aes(x=posi+1, y=to, size=10),show.legend = FALSE) +
geom_segment(data=temp, aes(x=posi, y=from, xend=posi+1, yend=to),
arrow=arrow(type="closed", angle=10), size=1.5, color="blue") + theme_bw()
But I would like to do it with Lattice because my real dataset is much bigger (millions of rows) and lattice works faster. I know I can reduce the number of lines removing duplicates but that's another story.
How can I do it with lattice?
I've been researchig and I think I need to use a panel.segments or lsegments, but things seem to be much more complicated and it's difficult to find examples.
xyplot(from ~ posi , type="p", col="black", data=temp, pch=16,
panel = function(x, y, ...){ panel.segments(x,y,) })
I don't know what parameters to write inside function nor inside panel.