# 3D plots: persp, contour, image # Planes x <- y <- seq(-5, 5, length=50) # For the third dimension, need to use the "outer" function z <- outer(x, y, "+") persp(x, y, z ) # For more complicated function, define a function f2 <- function(x, y){ x * sin(y) + y*sin(x)} z2 <- outer(x, y, "f2") persp( x, y, z2) persp(x, y, z2, theta=45, phi=45, col="slateblue") # For a list of colours: colors() colours() # Fancier x <- seq(-10, 10, length= 50) y <- x f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r } z <- outer(x, y, f) persp(x, y, z, theta=45, phi=30, col="skyblue") persp(x, y, z, theta=30, phi=45, col="orange") persp(x, y, z, theta = 30, phi = 30, col = "lightblue", ltheta = 120, shade = 0.75, ticktype = "detailed", xlab = "X", ylab = "Y", zlab = "sin(3x) cos(5y)" ) contour(x, y, z) image(x, y, z) image(x, y, z, col=rainbow(n=100)) image(x, y, z, col=terrain.colors(n=100)) #