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)
}
# \donttest{
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)
}
# }
Run the code above in your browser using DataLab