Graphics Reference
In-Depth Information
# 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
FALSE )
Figure 13-14. A 3D scatter plot
Viewers can rotate the image by clicking and dragging with the mouse, and zoom in and out
with the scroll wheel.
NOTE
By default, plot3d() uses square points, which do not appear properly when saving to a PDF. For im-
proved appearance, we used type="s" for spherical points, made them smaller with size=0.75 , and
turned off the 3D lighting with lit=FALSE (otherwise they look like shiny spheres).
Discussion
Three-dimensional scatter plots can be difficult to interpret, so it's often better to use a two-di-
mensional representation of the data. That said, there are things that can help make a 3D scatter
plot easier to understand.
In Figure 13-15 , we'll add vertical segments to help give a sense of the spatial positions of the
points:
Search WWH ::




Custom Search