Modification of rgl::axis3d() that adds three extra parameters,
ticksize, labeldist and tickangle, to independently control the
length of the axis tick marks, the distance between those tick marks and
their labels, and the direction (within the plane orthogonal to the axis)
in which both the tick marks and the labels are offset (see Details).
Based on the solution proposed on Stack Overflow (see References).
Usage
axis3(
edge,
at = NULL,
labels = TRUE,
tick = TRUE,
line = TRUE,
pos = NULL,
nticks = 5,
ticksize = 0.05,
tickangle = 45,
labeldist = 3,
...
)Arguments
- edge
character string indicating the edge of the bounding box on which the axis is drawn (same format as in
rgl::axis3d(), e.g."z+-").- at
positions at which the tick marks are drawn; if
NULLthey are computed automatically withpretty().- labels
tick labels: logical, indicating whether to automatically label the axes or be omitted, or a vector of labels.
- tick
logical; if
TRUEthe axis tick marks are drawn.- line
logical; if
TRUEthe axis line is drawn.- pos
optional position of the axis (see
rgl::axis3d()).- nticks
approximate number of tick marks when
at = NULL.- ticksize
length of the tick marks, as a fraction of the distance to the center of the scene's range.
- tickangle
direction, in degrees, of the tick marks and labels within the plane orthogonal to the axis (e.g.
0= along the first perpendicular coordinate,90= along the second one,45= towards the corner of the bounding box).- labeldist
distance between the tick marks and the labels, as a multiple of
ticksize.- ...
additional arguments passed to
rgl::segments3d()andrgl::text3d().
Value
An rglId object (see rgl::lowlevel()) with the identifiers of the
rgl elements added (line, tick marks and labels).
Details
By default (tickangle = 45), tick marks and labels are offset
simultaneously along both coordinates perpendicular to the axis, towards
the corresponding corner of the bounding box.
The original behavior of axis3d() can be reproduced by setting
tickangle = 45 and ticksize = 0.05 * sqrt(2) (the actual relative
length of the tick marks).
References
Dominic Woolf (2013, Mar 23). R rgl distance between axis ticks and tick labels, Stack Overflow, https://stackoverflow.com/a/39299740/4303451.
Examples
library(rgl)
open3d() # Alternatively, use `new3d()` to clear the current device or open a new one
set.seed(1)
points3d(rnorm(100), rnorm(100), rnorm(100))
box3d()
# Draw several z axis at z+- and z--, with longer tick marks and
# labels closer to them than usual
axis3('z+-', ticksize = 0.5, labeldist = 1)
axis3('z+-', ticksize = 0.5, labeldist = 1, tickangle = 0)
axis3('z--', ticksize = 0.5, labeldist = 1, tickangle = 90)
3D plot