Learn R Programming

fields (version 1.7.2)

as.image: Creates image from irregular x,y,z

Description

Discretizes a set of 2-d locations to a grid and produces a image object with the z values in the right cells. For cells with more than one Z value the average is used.

Usage

as.image(Z, ind, grid=NULL, x=NULL, nrow=64, ncol=64,weights=rep( 1,
length(Z)), na.rm=TRUE)

Arguments

Value

An list in image format with a few more components. Components x and y are the grid values , z is a nrow X ncol matrix with the Z values. NA's are placed at cell locations where Z data has not been supplied. Component ind is a 2 column matrix with subscripts for the locations of the values in the image matrix. Component N is an image matrix with the number of original values that fall within each grid box. Component weights is an image matrix with the sum of the individual weights for each cell.

Details

The discretization is straightforward once the grid is determined. If two or more Z values have locations in the same cell the average value is taken as the value. See the source code to modify this to get more information about coincident locations. (See the call to fast.1way)

See Also

image.smooth, image.plot, Krig.discretize, Krig.replicates, image.count

Examples

Run this code
# convert precip data to 50X50 image  
look<- as.image( RMprecip$y, x= RMprecip$x, nrow=50, ncol=50)
image.plot( look) 

# number of obs in each cell.
image.plot( look$x ,look$y, look$N, col=terrain.colors(50)) 
# hot spot is around Denver

Run the code above in your browser using DataLab