# create a grid with no data (just for coordinates)
(grid <- grd(nx = 2, ny = 2))
as_rct(grid)
as_xy(grid)
plot(grid, border = "black")
# more usefully, wraps a matrix or nd array + bbox
# approx volcano in New Zealand Transverse Mercator
bbox <- rct(
5917000, 1757000 + 870,
5917000 + 610, 1757000,
crs = "EPSG:2193"
)
(grid <- grd_rct(volcano, bbox))
# these come with a reasonable default plot method for matrix data
plot(grid)
# you can set the data or the bounding box after creation
grid$bbox <- rct(0, 0, 1, 1)
# subset by indices or rct
plot(grid[1:2, 1:2])
plot(grid[c(start = NA, stop = NA, step = 2), c(start = NA, stop = NA, step = 2)])
plot(grid[rct(0, 0, 0.5, 0.5)])
Run the code above in your browser using DataLab