
Last chance! 50% off unlimited learning
Sale ends in
as.surface(grid.list, z, order.variables="xy")
If zimage is matrix of values then the input vector is c( zimage). To go from the stacked vector to the matrix one needs the the nrow ncol and explains why grid information must also be specified. Note that the z input argument must be in the order values in order of stacking columns of the image. This is also the order of the grid points generated by make.surface.grid.
To convert irregular 2-d data to a surface object where there are missing cells see the function as.image.
# Make a perspective of the surface Z= X**2 -Y**2
# Do this by evaluating quadratic function on a 25 X 25 grid
grid.l<-list( X= seq( -2,2,,25), Y= seq( -2,2,,25))
xg<-make.surface.grid( grid.l)
# xg is a 625X2 matrix that has all pairs of X and Y grid values
z<- xg[,1]**2 - xg[,2]**2
# now fold z in the matrix format needed for persp
out.p<-as.surface( xg, z)
persp( out.p)
# also try plot( out.p) to see the default plot for a surface object
Run the code above in your browser using DataLab