Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plot3d

3D scatterplot


Description

Draws a 3D scatterplot.

Usage

plot3d(x, ...)
## Default S3 method:
plot3d(x, y, z,  
	xlab, ylab, zlab, type = "p", 
	col, size, lwd, radius,
	add = FALSE, aspect = !add, 
	xlim = NULL, ylim = NULL, zlim = NULL, 
	forceClipregion = FALSE, ...)
## S3 method for class 'mesh3d'
plot3d(x, xlab = "x", ylab = "y", zlab = "z", type = c("shade", "wire", "dots"),
	add = FALSE, aspect = !add, ...)

Arguments

x, y, z

vectors of points to be plotted. Any reasonable way of defining the coordinates is acceptable. See the function xyz.coords for details.

xlab, ylab, zlab

labels for the coordinates.

type

For the default method, a single character indicating the type of item to plot. Supported types are: 'p' for points, 's' for spheres, 'l' for lines, 'h' for line segments from z = 0, and 'n' for nothing. For the mesh3d method, one of 'shade', 'wire', or 'dots'. Partial matching is used.

col

the color to be used for plotted items.

size

the size for plotted points.

lwd

the line width for plotted items.

radius

the radius of spheres: see Details below.

add

whether to add the points to an existing plot.

aspect

either a logical indicating whether to adjust the aspect ratio, or a new ratio.

xlim, ylim, zlim

If not NULL, set clipping limits for the plot.

forceClipregion

Force a clipping region to be used, whether or not limits are given.

...

additional parameters which will be passed to par3d, material3d or decorate3d.

Details

plot3d is a partial 3D analogue of plot.default.

Missing values in the data are skipped, as in standard graphics.

If aspect is TRUE, aspect ratios of c(1, 1, 1) are passed to aspect3d. If FALSE, no aspect adjustment is done. In other cases, the value is passed to aspect3d.

With type = "s", spheres are drawn centered at the specified locations. The radius may be controlled by size (specifying the size relative to the plot display, with the default size = 3 giving a radius about 1/20 of the plot region) or radius (specifying it on the data scale if an isometric aspect ratio is chosen, or on an average scale if not).

Value

plot3d is called for the side effect of drawing the plot; a vector of object IDs is returned.

Clipping

If any of xlim, ylim or zlim are specified, they should be length two vectors giving lower and upper clipping limits for the corresponding coordinate. NA limits will be ignored.

If any clipping limits are given, then the data will be plotted in a newly created subscene within the current one; otherwise plotting will take place directly in the current subscene. This subscene is named "clipregion" in the results. This may affect the appearance of transparent objects if some are drawn in the plot3d call and others after, as RGL will not attempt to depth-sort objects if they are in different subscenes. It is best to draw all overlapping transparent objects in the same subscene. See the example in planes3d. It will also affect the use of clipplanes3d; clipping planes need to be in the same subscene as the objects being clipped.

Use forceClipregion = TRUE to force creation of this subscene even without specifying limits.

Author(s)

Duncan Murdoch

See Also

plot.default, open3d, par3d. There are plot3d.function and plot3d.deldir methods for plotting surfaces.

Examples

open3d()
  x <- sort(rnorm(1000))
  y <- rnorm(1000)
  z <- rnorm(1000) + atan2(x, y)
  plot3d(x, y, z, col = rainbow(1000))

rgl

3D Visualization Using OpenGL

v0.106.8
GPL
Authors
Duncan Murdoch [aut, cre], Daniel Adler [aut], Oleg Nenadic [ctb], Simon Urbanek [ctb], Ming Chen [ctb], Albrecht Gebhardt [ctb], Ben Bolker [ctb], Gabor Csardi [ctb], Adam Strzelecki [ctb], Alexander Senger [ctb], The R Core Team [ctb, cph], Dirk Eddelbuettel [ctb], The authors of Shiny [cph], The authors of knitr [cph], Jeroen Ooms [ctb], Yohann Demont [ctb], Joshua Ulrich [ctb], Xavier Fernandez i Marin [ctb], George Helffrich [ctb], Ivan Krylov [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.