In this recipe, we will use a special library to make a three-dimensional surface plot for the volcano
dataset. The resulting plot will also be interactive so that we can rotate the visualization using a mouse to look at it from different angles.
For this recipe, we will use the rgl
package, so we must first install and load it:
install.packages("rgl") library(rgl)
We will only use the inbuilt volcano
dataset, so we need not load any other dataset.
Let's make a simple three-dimensional surface plot that shows the terrain of the Maunga Whau volcano:
z <- 2 * volcano x <- 10 * (1:nrow(z)) y <- 10 * (1:ncol(z)) zlim <- range(z) zlen <- zlim[2] - zlim[1] + 1 colorlut <- terrain.colors(zlen) col <- colorlut[ z-zlim[1]+1 ] rgl.open() rgl.surface(x, y, z, color=col, back="lines")