Skip to contents

A generic function that, by default, draws a 3D scatter plot (rgl::plot3d()) with points colored according to a continuous scale associated with a vector of values s, and (optionally) adds a color-bar legend (via splot3d()).

Usage

spoints3d(x, ...)

# Default S3 method
spoints3d(
  x,
  y = NULL,
  z = NULL,
  s,
  slim = range(s, finite = TRUE),
  col = jet.colors(128),
  xlab = NULL,
  ylab = NULL,
  zlab = NULL,
  type = "p",
  legend = TRUE,
  legend.zoom = 0.4,
  legend.width = 0.1,
  legend.dim = 0.2,
  legend.lab = NULL,
  box = TRUE,
  lab.breaks = NULL,
  lab.ticksize = 0.5,
  lab.dist = 3,
  add = FALSE,
  ...
)

Arguments

x

object used to select a method. In the default method, it provides the x coordinates for the plot (and optionally the y and z coordinates; any reasonable way of defining the coordinates is acceptable, see the function xyz.coords() for details).

...

additional arguments passed to rgl::plot3d() for the main scatter plot (e.g. size).

y, z

y and z point coordinates. Alternatively, a single argument x can be provided.

s

vector used to color the points.

slim

limits (vector of length 2 with the minimum and maximum) used to set up the color scale.

col

color table used to set up the color scale. Defaults to jet.colors(128).

xlab, ylab, zlab

labels for the coordinates.

type

character indicating the type of item to plot (see rgl::plot3d(): "p" for points, "s" for spheres, "l" for lines, "h" for line segments from z = 0, and "n" for nothing).

legend

logical; if TRUE (default), the active rgl device is splitted into two subscenes, drawing the main plot in one and the categorical legend in the other (see fplot3d()). if FALSE only the (coloured) main plot is drawn and the arguments related to the legend are ignored (fplot3d() is not called).

legend.zoom

zoom factor applied to the legend subscene (see rgl::view3d()).

legend.width

relative width of the color bar, as a fraction of the corresponding dimension of the legend subscene/panel.

legend.dim

relative dimension of the legend panel, as a fraction of the full width (or height) of the device.

legend.lab

legend title.

box

logical; if TRUE (the default) a rectangle is drawn around the color bar.

lab.breaks

labels for the legend axis breaks; if NULL they are generated automatically (see axis3()).

lab.ticksize

length of the legend axis tick marks, as a fraction of the distance to the center of the legend panel.

lab.dist

distance between the tick marks and the labels of the legend axis, as a multiple of lab.ticksize.

add

logical; if TRUE the scatter plot is just added to the existing plot (including the legend if legend = TRUE).

Value

Called for its side effect (draws the 3D scatter plot and, unless legend = FALSE, the legend on the active rgl device).

Examples

library(rgl)
open3d() # Alternatively, use `new3d()` to clear the current device or open a new one
with(mtcars, spoints3d(hp, qsec, wt, s = mpg, type = "s"))