Learn R Programming

physx (version 1.0)

griddata2: Grid 2D point set

Description

Generates a 2D grid from a 2D point set, optionally with weights

Usage

griddata2(x, y = NULL, w = NULL, n = c(20, 20), xlim = NULL, ylim = NULL)

Arguments

x

N-element vector of x-coordinates or N-by-2 matrix of (x,y)-coordinates

y

N-element vector of y-coordinates (only used if x is a vector)

w

optional N-element vector with weights

n

scalar or 2-element vector specifying the number of equally space grid cells along each direction.

xlim

2-element vector specifying the x-range (data cropped if necessary). If not given, xlim is set to the range of x.

ylim

2-element vector specifying the y-range (data cropped if necessary). If not given, ylim is set to the range of y.

Value

Returns a list of items

x

n-element vector of cell-center x-coordinates

y

n-element vector of cell-center y-coordinates

xbreak

(n+1)-element vector of cell-edge x-coordinates

ybreak

(n+1)-element vector of cell-edge y-coordinates

dx

spacing between x-coordinates

dy

spacing between y-coordinates

xlim

range of xbreak, same as input argument xlim, if given

ylim

range of ybreak, same as input argument ylim, if given

n

2D array of point counts.

d

normalized number densities corresponding to n, such that sum(d)*dx*dy=1.

m

2D array of weighted point counts (masses); only available if w is specified.

c

2D array of normalized mass densities corresponding to m, such that sum(c)*dx*dy=1; only available if w is specified.

See Also

griddata

Examples

Run this code
# NOT RUN {
x = runif(100,min=0,max=2)
y = runif(100,min=0,max=1)
g = griddata2(x,y,xlim=c(0,2),ylim=c(0,1),n=c(20,10))
image(g$xbreak,g$ybreak,g$n,asp=1,col=grey.colors(100,0,1))
points(x,y,col='red',pch=20,cex=0.5)

# }

Run the code above in your browser using DataLab