3-D Scatter plots

3-D scatter plots (as distinct from scatter plot matrices involving three variables), illustrate the relationship among three variables by plotting them in a three-dimensional "workbox".  There are a number of basic enhancements of the basic 3-D scatter plot, such as the addition of drop lines, lines connecting points, symbol modification and so on.

3-D Point cloud plot

Displays the values of three variables at a time by plotting them in a 3-D workbox, where the value of one variable determines the relative position of the symbol along the X-axis and the value of a second variable determines the relative position of the symbol along the Y-axis, and the value of the third variable is used to determine the relative position along the Z-axis.

library(lattice)
attach(orstationc)
cloud(elev ~ lon*lat)

3-D Scatter plots (using the scatterplot3d package)

The scatterplot3d package (by Ligges and Mächler) provide a way of constructing a 3-point cloud display with some nice embelishments.

library(scatterplot3d)
library(RColorBrewer)
attach(orstationc)

# get colors for labeling the points
plotvar <- pann # pick a variable to plot
nclr <- 8 # number of colors
plotclr <- brewer.pal(nclr,"PuBu") # get the colors
colornum <- cut(rank(plotvar), nclr, labels=FALSE)
colcode <- plotclr[colornum] # assign color

# scatter plot
plot.angle <- 45
scatterplot3d(lon, lat, plotvar, type="h", angle=plot.angle, color=colcode, pch=20, cex.symbols=2, col.axis="gray", col.grid="gray")

Maps can be added to the 3-D scatter plot to improve interpretability:

library(scatterplot3d)
library(maps)
library(RColorBrewer)
attach(orstationc)

# get points that define Oregon county outlines
or.map <- map("county", "oregon", xlim=c(-125,-114), ylim=c(42,47), plot=F)

# get colors for labeling the points
plotvar <- pann # pick a variable to plot
nclr <- 8 # number of colors
plotclr <- brewer.pal(nclr,"PuBu") # get the colors
colornum <- cut(rank(plotvar), nclr, labels=FALSE)
colcode <- plotclr[colornum] # assign color

# scatterplot and map
plot.angle <- 135
s3d <- scatterplot3d(lon, lat, plotvar, type="h", angle=plot.angle, color=colcode, pch=20, cex.symbols=2, col.axis="gray", col.grid="gray")
s3d$points3d(or.map$x,or.map$y,rep(0,length(or.map$x)), type="l")

OpenGL surface and point plots

The rgl package (by D. Alder) can be used to plot points (and surfaces and lines) in a 3-D space.  The main feature that distinguishes this approach is the ability to rotate the cloud of points "on the fly"

library(rgl)
example(rgl.surface)

rgl.clear()
example(rgl.spheres)

Plot a gridded data set of Oregon climate data (elevation in this example) [orgrid.csv]:

library(rgl)
library(RColorBrewer)
attach(orgrid)

plotvar <- elev # pick a variable to plot
nclr <- 8 # number of colors
plotclr <- brewer.pal(nclr,"PuOr") # get the colors
colornum <- cut(rank(plotvar), nclr, labels=FALSE)
colcode <- plotclr[colornum] # assign color

x <- (lon-min(lon))/(max(lon)-min(lon))
y <- (lat-min(lon))/(max(lat)-min(lat))
z <- (plotvar-min(plotvar))/(max(plotvar)-min(plotvar))

rgl.clear()
rgl.points(x, y, z/2, color=colcode, size=4)
rgl.bbox(color="#333377", emission="#333377", specular="#3333FF",
     shininess=5, alpha=0.8 )

Plot the SPECMAP data:

attach(specmap)
x <- (Age-min(Age))/(max(Age)-min(Age))
y <- (O18-min(O18))/(max(O18)-min(O18))
z <- (Insol-min(Insol))/(max(Insol)-min(Insol))

rgl.clear()
rgl.bbox(color="#333377", emission="#333377", specular="#3333FF",
     shininess=5, alpha=0.8 )
rgl.points(x, y, z, size=4)
rgl.texts(.9, 0, 1, "-Age", col="red")
rgl.texts(.1, 0, 1, "Age+", col="red")
rgl.texts(0, 0, .9, "+Insol", col="red")
rgl.texts(0, 0, .1, "-Insol", col="red")
rgl.texts(0, .9, 0, "+O18", col="red")
rgl.texts(0, .1, 0, "-O18", col="red")