ggplot_projection_shapefile: Plot a raster (either a raster layer or a inla projection...

Description Usage Arguments Examples

View source: R/ggplot_projection_shapefile.R

Description

Plot a raster (either a raster layer or a inla projection matrix) with a shape file

Usage

1
2
ggplot_projection_shapefile(raster = NULL, projector = NULL,
  spatialpolygons = NULL, mesh = NULL, shapecol = "white")

Arguments

raster

Either a RasterLayer or a matrix (e.g. from inla.mesh.project)

projector

If raster is a matrix, a projector object (from inla.mesh.projector) is also needed.

spatialpolygons

A SpatialPolygonsDataFrame object.

mesh

An inla.mesh object to be plotted. Still rough.

shapecol

Colour for the shape file outlines.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## 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)

## End(Not run)

INLAutils documentation built on Dec. 6, 2017, 5:06 p.m.