fm_pixels | R Documentation |
Generate terra
, sf
, or sp
lattice locations
fm_pixels(
mesh,
dims = c(150, 150),
xlim = NULL,
ylim = NULL,
mask = TRUE,
format = "sf",
minimal = TRUE,
nx = deprecated(),
ny = deprecated()
)
sf
, SpatRaster
, or SpatialPixelsDataFrame
covering the mesh or
mask.
Finn Lindgren finn.lindgren@gmail.com
if (require("ggplot2", quietly = TRUE)) {
dims <- c(50, 50)
pxl <- fm_pixels(
fmexample$mesh,
dims = dims,
mask = fmexample$boundary_sf[[1]],
minimal = TRUE
)
pxl$val <- rnorm(NROW(pxl)) +
fm_evaluate(fmexample$mesh, pxl, field = 2 * fmexample$mesh$loc[, 1])
ggplot() +
geom_tile(
data = pxl,
aes(geometry = geometry, fill = val),
stat = "sf_coordinates"
) +
geom_sf(data = fm_as_sfc(fmexample$mesh), alpha = 0.2)
}
if (require("ggplot2", quietly = TRUE) &&
require("terra", quietly = TRUE) &&
require("tidyterra", quietly = TRUE)) {
pxl <- fm_pixels(fmexample$mesh,
dims = c(50, 50), mask = fmexample$boundary_sf[[1]],
format = "terra"
)
pxl$val <- rnorm(NROW(pxl) * NCOL(pxl))
pxl <-
terra::mask(
pxl,
mask = pxl$.mask,
maskvalues = c(FALSE, NA),
updatevalue = NA
)
ggplot() +
geom_spatraster(data = pxl, aes(fill = val)) +
geom_sf(data = fm_as_sfc(fmexample$mesh), alpha = 0.2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.