plot_env() rasterises, which is right for a regular grid and wrong for an
FVCOM mesh: a triangulation has no rows and columns to rasterise onto, so the
result is either blocky or interpolated over cells the model does not have.
This draws the geometry it is given.
Usage
plot_mesh(
x,
var = NULL,
values = NULL,
time = 1,
palette = "viridis",
border = NA,
main = NULL,
...
)Arguments
- x
an
sfobject with polygon or point geometry — typically fromfvcom_mesh(), but anysfobject works- var
which column to shade by;
NULLdraws the bare geometry- values
optional
sfobject holding the values, fromaccessFVCOM()or any access function. Joined toxspatially.- time
which time step of
valuesto use, as an index or a named vector ofYEAR/MONTH/DAY. Only needed whenvaluescarries more than one.- palette
a
grDevices::hcl.colors()palette name- border
colour for cell edges.
NAhides them, which is what you want on a fine mesh where the edges would otherwise be all you see.- main
plot title
- ...
passed to
plot()
What it is for
Two jobs. With a mesh from fvcom_mesh() and nothing else, it draws the grid
itself — which is how you see where a model resolves a shelf finely and where
it does not. With var naming a column, it shades each cell by that value.
Shading a mesh with fetched values
accessFVCOM() returns points and fvcom_mesh() returns triangles, so the
two are joined spatially rather than by position — a fetch is subset to the
bounding box, so its row order says nothing about the mesh's own numbering.
Pass values and that join is done for you:
mesh <- fvcom_mesh(bounding_box = bb)
sst <- accessFVCOM(vars = "SST", years = 2010, months = 6, bounding_box = bb)
plot_mesh(mesh, "SST", values = sst)Element-centred values (UO, UBAR, TAUX) sit at the centroid, one per
triangle. Node-centred ones (SST, BOTS) sit at the corners, shared
between the triangles meeting there, so each triangle takes the mean of its
three — which is why the join tests intersection rather than containment: a
corner is on the boundary, and nothing contains it.
See also
fvcom_mesh() for the grid, plot_env() for regular grids
Examples
if (FALSE) { # \dontrun{
bb <- list(xmin = -70, xmax = -66, ymin = 41, ymax = 44)
mesh <- fvcom_mesh(bounding_box = bb)
plot_mesh(mesh) # the grid itself
plot_mesh(mesh, "DEPTH") # shaded by bathymetry
sst <- accessFVCOM(vars = "SST", years = 2010, months = 6, bounding_box = bb)
plot_mesh(mesh, "SST", values = sst)
} # }