Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
We’ll use the rgl package, which provides an
interface to the OpenGL graphics library for 3D graphics. To create a 3D scatter plot, as in Figure 13-14, use plot3d() and pass
in a data frame where the first three columns represent
x, y, and
z coordinates, or pass in three vectors
representing the x, y, and
z coordinates.
# You may need to install first, with install.packages("rgl")library(rgl)plot3d(mtcars$wt,mtcars$disp,mtcars$mpg,type="s",size=0.75,lit=FALSE)
Viewers can rotate the image by clicking and dragging with the mouse, and zoom in and out with the scroll wheel.