I am looking for advice on plotting vectors in the cartesian plane. The task is to plot points (coordinates) and then to link them with an arrow to some source point (say 0,0). The image below should give an idea. I don't care about colours and naming vectors/points, it's just about plotting arrows in the coordinate plane. I am sure some library exists in R (or python) for plotting linear algebra vectors and operations.
Any pointers would be appreciated!
Or you can use
arrows function in R.
plot(NA, xlim=c(0,5), ylim=c(0,5), xlab="X", ylab="Y") vecs <- data.frame(vname=c("a","b","a+b", "transb"), x0=c(0,0,0,2),y0=c(0,0,0,1), x1=c(2,1,3,3) ,y1=c(1,2,3,3), col=1:4) with( vecs, mapply("arrows", x0, y0, x1,y1,col=col) )
It will look a bit better if you add lwd=3 to the
arrows call. The
text function would allow labeling and can be rotated with the 'srt' parameter.
plot(NA, xlim=c(0,5), ylim=c(0,5), xlab="X", ylab="Y", lwd=3) with( vecs, mapply("arrows", x0, y0, x1,y1,col=col,lwd=3) ) with(vecs, mapply('text', x=x1[1:3]-.1, y=y1[1:3]+.1, labels=expression(list(a,a), list(b,b), list(a+b,a+b) ) ))
PLease note that the
list function inside the
expression call is a plotmath
list-call, different than the regular R
list just as plotmath-
paste is different than regular
paste. It does not make any attempt to evaluate its argument in the parent-frame. For that one would need
substitute and would probably need to use
sapply be used to process the "interior" expressions.