as.surface: Creates an "surface" object from grid values.

View source: R/as.surface.R

as.surfaceR Documentation

Creates an "surface" object from grid values.

Description

Reformats the vector from evaluating a function on a grid of points into a list for use with surface plotting function. The list has the usual components x,y and z and is suitable for use with persp, contour, image and image.plot.

Usage

as.surface(obj, z, location=NULL, order.variables="xy")

Arguments

obj

A description of the grid used to evaluate the function. This can either be in the form of a grid.list ( see help file for grid.list) or the matrix of grid of points produced by make.surface.grid. In the later case obj is a matrix with the grid.list as an attribute.

z

The value of the function evaluated at the gridded points.

location

A logical or two column matrix of indices indicating the location of the z values within the image matrix.

order.variables

Either "xy" or "yx" specifies how the x and y variables used to evaluate the function are matched with the x and y grids in the surface object.

Details

This function was written to simply to go back and forth between a matrix of gridded values and the stacked vector obtained by stacking columns. The main application is evaluating a function at each grid point and then reforming the results for plotting. (See example below.)

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.

Value

A list of class surface. This object is a modest generalization of the list input format (x,y,z,) for the S functions contour, image or persp.

x

The grid values in the X-axis

y

The grid values in the Y-axis

z

A matrix of dimensions nrow= length of x and ncol= length of y with entries being the grid point value reformatted from z.

See Also

grid.list, make.surface.grid, surface, contour, image.plot, as.image

Examples

 

# 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( abcissa= seq( -2,2,,15), ordinate= seq( -2,2,,20)) 
xg<-make.surface.grid( grid.l)
# xg is a 300X2 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 

fields documentation built on June 28, 2024, 1:06 a.m.

Related to as.surface in fields...