make.grid: Create grd object

View source: R/make.grid.R

make.gridR Documentation

Create grd object

Description

Create a grd object from x, y and z data. For use with draw.grid and write.grid.

Usage

make.grid(x, y, z, byx , byy , xlim, ylim, fun = function(x) sum(x, na.rm = T))

Arguments

x

a vector of x-coordinates (longitude)

y

a vector of y-coordinates (latitude; same length as x)

z

a vector of values; same length as x

byx, byy

the size of the grid cells on the x and y scale

xlim, ylim

the x and y limits of the grid. Note that the origin of the grid depends on xlim[1] and ylim[1], these values will be taken as the mid-point of the bottom-left grid-cell. See example below how to use this to create a grid that matches that of the ICES rectangles.

fun

a function to be applied to z. Defaults to sum.

Details

Due to the way fractions are stored in binary format, rounding errors can occur, e.g.:

as.character(seq(-5,0,by=0.8))

results in:

"-5" "-4.2" "-3.4" "-2.6" "-1.8" "-1" "-0.199999999999999"

this can affect the make.grid function although this is generally not a problem.

Value

a grd object, which is simply a 2-dimensional array with row and column names that correspond to the x and y positions of the grid.

Author(s)

Hans Gerritsen

See Also

draw.grid

Examples

data(coast)
data(landings)
byx = 1
byy = 0.5
xlim <- c(-15.5,0)
ylim <- c(50.25,56)
grd <- make.grid(landings$Lon,landings$Lat,landings$LiveWeight, byx, byy, xlim, ylim)
breaks <- breaks.grid(grd,zero=FALSE)
basemap(xlim, ylim, main = "Gadoid landings")
draw.grid(grd,breaks)
draw.shape(coast, col="darkgreen")
legend.grid("topright", breaks=breaks/1000, type=2, inset=0.02, title="tonnes")

mapplots documentation built on Aug. 25, 2023, 5:15 p.m.