vectors | R Documentation |
This function draws vectors in a 2D plot, in a way that facilitates constructing vector diagrams. It allows vectors to be specified as rows of a matrix, and can draw labels on the vectors.
vectors(
X,
origin = c(0, 0),
lwd = 2,
angle = 13,
length = 0.15,
labels = TRUE,
cex.lab = 1.5,
pos.lab = 4,
frac.lab = 1,
...
)
X |
a vector or two-column matrix representing a set of geometric vectors; if a matrix, one vector is drawn for each row |
origin |
the origin from which they are drawn, a vector of length 2. |
lwd |
line width(s) for the vectors, a constant or vector of length equal to the number of rows of |
angle |
the |
length |
the |
labels |
a logical or a character vector of labels for the vectors. If |
cex.lab |
character expansion applied to vector labels. May be a number or numeric vector corresponding to the the
rows of |
pos.lab |
label position relative to the label point as in |
frac.lab |
location of label point, as a fraction of the distance between |
... |
other arguments passed on to graphics functions. |
none
arrows
, text
Other vector diagrams:
Proj()
,
arc()
,
arrows3d()
,
circle3d()
,
corner()
,
plot.regvec3d()
,
pointOnLine()
,
regvec3d()
,
vectors3d()
# shows addition of vectors
u <- c(3,1)
v <- c(1,3)
sum <- u+v
xlim <- c(0,5)
ylim <- c(0,5)
# proper geometry requires asp=1
plot( xlim, ylim, type="n", xlab="X", ylab="Y", asp=1)
abline(v=0, h=0, col="gray")
vectors(rbind(u,v,`u+v`=sum), col=c("red", "blue", "purple"), cex.lab=c(2, 2, 2.2))
# show the opposing sides of the parallelogram
vectors(sum, origin=u, col="red", lty=2)
vectors(sum, origin=v, col="blue", lty=2)
# projection of vectors
vectors(Proj(v,u), labels="P(v,u)", lwd=3)
vectors(v, origin=Proj(v,u))
corner(c(0,0), Proj(v,u), v, col="grey")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.