Learn R Programming

plot3Drgl (version 1.0.4)

persp3Drgl: 3-D plotting functions using rgl.

Description

Functions persp3Drgl, ribbon3Drgl, hist3Drgl produce perspective plots using rgl; they are similar to functions persp3D, ribbon3D, hist3D from package plot3D.

Functions scatter3Drgl, points3Drgl, lines3D, segments3Drgl produce scatter plots and line plots using rgl; they are similar to functions scatter3D, points3D, lines3D, segments3D from package plot3D.

Functions slice3Drgl, points3Drgl, isosurf3Drgl, voxel3Drgl can visualise volumetric (3D) data using rgl; they are similar to functions slice3D, slicecont3D, isosurf3D, voxel3D from package plot3D.

Functions surf3Drgl, spheresurf3Drgl produce surface plots using rgl; they are similar to functions surf3D, spheresurf3D from package plot3D.

Functions box3Drgl, border3Drgl, rect3Drgl, text3Drgl produce boxes, rectangles, texts to 3D plots using rgl; they are similar to functions box3D, border3D, rect3D, text3Drgl from package plot3D.

Usage

persp3Drgl(...) 
ribbon3Drgl(...)
hist3Drgl(...)
scatter3Drgl(...)
points3Drgl(...)
lines3Drgl(...)
slice3Drgl(...)
slicecont3Drgl(...)
isosurf3Drgl(...)
voxel3Drgl(...)
triangle3Drgl(...)
surf3Drgl(...)
spheresurf3Drgl(...)
segments3Drgl(...)
image3Drgl(...)
contour3Drgl(...)
box3Drgl(...)
border3Drgl(...)
rect3Drgl(...)
text3Drgl(...)

Arguments

...

arguments passed to the plotting methods of package plot3D, or to the plotrgl method. The following persp arguments can be specified: xlim, ylim, zlim, xlab, ylab, zlab, main, sub, r, d, scale, expand, box, axes, nticks, ticktype, shade, ltheta, lphi. In addition, the perspbox arguments col.axis, col.panel, lwd.panel, col.grid, lwd.grid can also be given a value.

Author

Karline Soetaert <karline.soetaert@nioz.nl>

Details

The first step in 3D rgl plotting consists in calling the corresponding 3-D function from package plot3D with argument plot set to FALSE.

The next step is to create a 3-D rgl plot, by calling plotrgl.

The actions of the mouse on the plots is to zoom (left, middle), and to move it (right key).

See Also

plotdev to plot first in ordinary R graphics and then in rgl

for plotrgl to plot first in ordinary R graphics and then in rgl

cutrgl for cutting a rectangular region from the rgl plot.

Examples

Run this code

## =======================================================================
## perspective plots
## =======================================================================
 persp3Drgl(z = volcano, contour = list(side = "zmax"))

# ribbon, in x--direction
 V <- volcano[seq(1, nrow(volcano), by = 5), 
              seq(1, ncol(volcano), by = 5)]  # lower resolution
 ribbon3Drgl(z = V, ticktype = "detailed")
 hist3Drgl(z = V, col = "grey", border = "black", lighting = TRUE)
 
if (FALSE) {
  cutrgl()    # select a rectangle
  uncutrgl()
}

## =======================================================================
## scatter points
## =======================================================================

 with(quakes, scatter3Drgl(x = long, y = lat, z = -depth, 
   colvar = mag, cex = 3))

 plotdev()   # plots same on oridinary device...
 
## =======================================================================
## 3D surface
## =======================================================================

 M  <- mesh(seq(0, 2*pi, length.out = 50), 
            seq(0, 2*pi, length.out = 50))
 u  <- M$x ; v  <- M$y

 x  <- sin(u)
 y  <- sin(v)
 z  <- sin(u + v)

# alpha makes colors transparent
 surf3Drgl(x, y, z, colvar = z, border = "black", smooth  = TRUE, 
   alpha = 0.2)

## =======================================================================
## volumetric data
## =======================================================================
 x <- y <- z <- seq(-4, 4, by = 0.2)
 M <- mesh(x, y, z)

 R <- with (M, sqrt(x^2 + y^2 + z^2))
 p <- sin(2*R) /(R+1e-3)

 slice3Drgl(x, y, z, colvar = p, col = jet.col(alpha = 0.5), 
         xs = 0, ys = c(-4, 0, 4), zs = NULL, d = 2) 

Run the code above in your browser using DataLab