Creating three-dimensional surface plots
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:
We will only use the inbuilt
volcano dataset, so we need not load any other dataset.
How to do it...
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 - zlim + 1 colorlut <- terrain.colors(zlen) ...