Reputation: 291
I have two vectors, x and y, containing the coordinates to plot. But I would like to plot, for each of them, an arrow starting from the origin to the coordinate, instead of just a point. Using "arrows" seems not so handy, since I should manually add the coordinate in the form
arrows(x0, y0, x1, y1)
etc...
Is there some smarter way to deal with the problem? Thanks in advance
Upvotes: 1
Views: 1996
Reputation: 14842
Try this
x <- runif(10)
y <- runif(10)
plot(x, y, type="n", xlim=c(0, max(x)), ylim=c(0, max(y)))
arrows(0, 0, x, y)
arrows
can only add content to an existing plot, but cannot used not create a new plot. By first calling plot
you set up the plot, creating axes, labels, etc., but type="n"
tells R to hide all contents in the plot area (i.e. the points). After that you can go ahead and add the arrows.
Upvotes: 5