sesselastronaut sesselastronaut - 8 months ago 46
R Question

Draw arrows in 3D, based on package rgl

I would like to draw 3D arrows in my plot3d plot using the rgl library as mentioned for example here.
But apparently arrows3d is not part of the package, is it deprecated or future music as


No vignettes or demos or help files found with alias or concept or title matching ‘arrows3D’ using fuzzy matching.


The latest rgl (version 0.95.1470, available only on R-forge at the moment; see How do I install the latest version of rgl? for how to get it) has a function arrow3d() modelled after the heplots::arrow3d function, but expanded quite a bit.

It can draw arrows like the heplots function (i.e. made up of line segments), or as flat polygons, or as extrusions of polygons, or as rotations of polygons. The ?arrow3d help example currently does this:

xyz <- matrix(rnorm(300), ncol = 3)
arrow3d(xyz[1,], xyz[2,], type = "extrusion", col = "red")
arrow3d(xyz[3,], xyz[4,], type = "flat",      col = "blue")
arrow3d(xyz[5,], xyz[6,], type = "rotation",  col = "green")
arrow3d(xyz[7,], xyz[8,], type = "lines",     col = "black")
arrow3d(spriteOrigin = xyz[9:12,],            col = "purple")

which produces this output:

arrow3d example

Normally it draws just one arrow per call, but if you ask for 3D sprites (as in the purple example) it can draw multiple copies of the same arrow.