# plotting using the package plot3D library(plot3D) # first, let's create some data to work with d = volcano View(d) x = seq(-pi, pi, by = 0.2) y = seq(-pi, pi, by = 0.2) z = cos(x) * sin(y) grid = mesh(x, y) z.mat = with(grid, cos(x) * sin(y)) # scatterplots help(scatter2D) scatter2D(x = x, y = y, colvar = z) scatter2D(x = x, y = y, colvar = z, type = "l") scatter3D(x = x, y = y, z = z) scatter3D(x = x, y = y, z = z, type = "l") # contour plots help(contour2D) contour2D(z = d) image2D(z = d) contour3D(z = d, colvar = d, nlevels = 20) # perspective plots help(persp3D) persp3D(z = d) persp3D(z = z.mat) ribbon3D(z = z.mat) hist3D(z = z.mat) # The plots are produced by first transforming the (x,y,z) coordinates to the interval [0,1] using the limits supplied or computed from the range of the data. The surface is then viewed by looking at the origin from a direction defined by theta and phi. If theta and phi are both zero the viewing direction is directly down the negative y axis. Changing theta will vary the azimuth and changing phi the colatitude. persp3D(z = z.mat, phi = 40, theta = 40) persp3D(z = z.mat, phi = 0, theta = 0) persp3D(z = z.mat, phi = 40, theta = 0) persp3D(z = z.mat, phi = 0, theta = 0) persp3D(z = z.mat, phi = 0, theta = 40)