mapplots (version 1.5.1)

make.grid: 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))

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.

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.

Author

Hans Gerritsen

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.

See Also

draw.grid

Examples

Run this code
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")

Run the code above in your browser using DataLab