October 2011
Beginner to intermediate
400 pages
9h 30m
English
R offers a number of functions to plot data in three dimensions such as persp() and wireframe(), which draw surfaces, and cloud(), which draws three-dimensional scatter plots. Here, we’ll look at a simple example that uses wireframe().
> library(lattice) > a <- 1:10 > b <- 1:15 > eg <- expand.grid(x=a,y=b) > eg$z <- eg$x^2 + eg$x * eg$y > wireframe(z ~ x+y, eg)
First, we load the lattice library. Then the call to expand.grid() creates a data frame, consisting of two columns named x and y, in all possible combinations of the values of the two inputs. Here, a and b had 10 and 15 values, respectively, so the resulting data frame will have 150 rows. (Note that the data frame that is input to wireframe() does not need ...
Read now
Unlock full access