# NOT RUN {
set.seed(2)
library(INLA)
# Create inla projector
n <- 20
loc <- matrix(runif(n*2), n, 2)
mesh <- inla.mesh.create(loc, refine=list(max.edge=0.05))
projector <- inla.mesh.projector(mesh)
field <- cos(mesh$loc[,1]*2*pi*3)*sin(mesh$loc[,2]*2*pi*7)
projection <- inla.mesh.project(projector, field)
# And the shape file
crds <- loc[chull(loc), ]
SPls <- SpatialPolygons(list(Polygons(list(Polygon(crds)), ID = 'a')))
ggplot_projection_shapefile(projection, projector, SPls) + theme_minimal()
# Alternatively plot a raster
library(raster)
raster <- raster(projection)
extent(raster) <- c(range(projector$x), range(projector$y))
ggplot_projection_shapefile(raster, spatialpolygons = SPls)
# }
Run the code above in your browser using DataLab