Skip to Main Content
Graphing Data with R
book

Graphing Data with R

by John Jay Hilfiger
October 2015
Beginner to intermediate content levelBeginner to intermediate
250 pages
6h 26m
English
O'Reilly Media, Inc.
Content preview from Graphing Data with R

Chapter 17. Three-Dimensional Plots

3D Scatter plots

The trees dataset has three quantitative variables. We looked at the distribution of one of them, Volume, in a strip chart and the relationship of two of them, Height and Girth, in a scatter plot. It is possible to visualize all three at once in an extension of the scatter plot, a graph commonly called a 3D scatter plot. Several packages have functions to create 3D scatter plots, including lattice, scatterplot3d, rgl, plot3D, car, and probably others.

In this section, the scatterplot3d package is emphasized because its syntax is very much like that of the plot() function in base R. It is also relatively easy to work with and quite versatile. Finally, many of the tricks that you can use to make 3D plots comprehensible are easily demonstrated with this package. A couple of other functions will also be introduced and compared.

The scatterplot3d() function has a basic syntax of either:

scatterplot3d(x, optional arguments)

where x is a data frame or matrix,

or:

scatterplot3d(x, y, z, optional arguments)

where x, y, and z are vectors.

Although the first option is usually more convenient, the second is often preferable because it gives you the ability to decide upon the order of the variables or to select a subset of variables. Variable x is plotted on the horizontal axis, y on the diagonal axis, and z on the vertical axis. In the example script that follows, x, y, and z are Height, Girth, and Volume.

 # script for Figure 17-1 library(scatterplot3d) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

A Course in Statistics with R

A Course in Statistics with R

Prabhanjan N. Tattar, Suresh Ramaiah, B. G. Manjunath

Publisher Resources

ISBN: 9781491922606Errata Page