leveragePlot: Plot a map with leverage values as RGB colours. The leverage...

View source: R/leveragePlot.R

leveragePlotR Documentation

Plot a map with leverage values as RGB colours. The leverage values outputted from SDM profilinf for unsampled cells for three leverage categories are mapped on to the RGB values

Description

Plot a map with leverage values as RGB colours. The leverage values outputted from SDM profilinf for unsampled cells for three leverage categories are mapped on to the RGB values

Usage

leveragePlot(
  profile,
  origSDM,
  leverage_type = "dual-leverage",
  col = "red",
  plot_type = "points",
  save_plots = FALSE
)

Arguments

profile

the output from sdmProfiling

origSDM

a raster file of the probability of occurrences of the original SDM built using the sampled cells (i.e. those in 'sampledCoords')

leverage_type

which leverage type to plot. One of "redundancy}, \code{presence_leverage}, \code{absence_leverage} or \code{dual_leverage" (default)

col

the colour ramp to use (default = "red"). Low values are white

plot_type

either "points" (default) or "raster". Use "points" where you have profiled a subsample of unsampled cells. Each profiled cell will be represented by a point where point colour and size is the leverage value, and the background will be the original SDM map. If all unsampled cells have been profiled use "raster" will plot the profiled cells as a raster map, with cell colour representing the leverage value

save_plots

TRUE or FALSE (default) whether to save the final plot to a ggplot object

Value

Automatically generates a map of leverage values. If Use plot_type = "points" each profiled cell will be represented by a point with colour and size relative to the leverage value, and the background will be the original SDM map. If all unsampled cells have been profiled use "raster" will plot the profiled cells as a raster map, with cell colour representing the leverage value.

Optionally, if save_plot = TRUE will output the ggplot object.

Author(s)

Charlie Marsh (charlie.marsh@mailbox.org) & Yoni Gavish

Examples

set.seed(111)
envSet <- create_env_nsets(cellDims = c(25, 25),
                           sets     = c(2, 2, 2, 1),
                           model    = "Sph",
                           psill    = 1.5,
                           dep1     = 1,
                           rangeFun = function() exp(runif(1, 1, 6)),
                           propSamp = 0.1)

### generate a virtual species from the variables
sp <- create_sp(envStack = envSet,
                spFun    = "x[1] * x[3] * x[5]",
                spModel  = "Sph",
                spPsill  = 1,
                spRange  = 500,
                propSamp = 0.5,
                prev     = 0.25)

### an initial 'sample' of the species (assuming perfect detection)
sampPts <- data.frame(sampleRandom(sp$presence, 15, na.rm = TRUE, xy = TRUE))

### a formula to fit to random forest (additive for all vars + quadratics)
form <- paste0("presence ~ ", paste(names(envSet), collapse = " + "), "+ I(",
               paste(names(envSet), collapse = " ^ 2) + I("), " ^ 2)")

### run the initial model
spMod <- sdmModelling(samples = sampPts,
                      envStack = envSet,
                      modFormula = form,
                      ntrees = 500,
                      plot = FALSE)

### the full set of unsampled points to profile
unsampPts <- expand.grid(x = 1:25, y = 1:25)
unsampPts <- unsampPts[!paste(unsampPts$x, unsampPts$y) %in%
                         paste(sampPts$x, sampPts$y), ]

profile <- sdmProfiling(unsampledCoords = unsampPts,
                        sampledCoords   = sampPts,
                        origSDM         = spMod,
                        envStack        = envSet,
                        sdmFun          = "sdmModelling",
                        sdmFunArgs      = list(samples    = NULL,
                                               envStack   = envSet,
                                               modFormula = form,
                                               ntrees     = 100),
                        parallel = FALSE)

###
leveragePlot(profile = profile, origSDM = spMod, plot_type = "raster",
             leverage_type = "dual_leverage", col = "forest green")

leveragePlot(profile = profile, origSDM = spMod, plot_type = "raster",
             leverage_type = "presence_leverage", col = "red")


#' ### the full set of unsampled points to profile
unsampPts <- data.frame(x = sample(1:25, 25), y = sample(1:25, 25))
unsampPts <- unsampPts[!paste(unsampPts$x, unsampPts$y) %in%
                         paste(sampPts$x, sampPts$y), ]

profile <- sdmProfiling(unsampledCoords = unsampPts,
                        sampledCoords   = sampPts,
                        origSDM         = spMod,
                        envStack        = envSet,
                        sdmFun          = "sdmModelling",
                        sdmFunArgs      = list(samples    = NULL,
                                               envStack   = envSet,
                                               modFormula = form,
                                               ntrees     = 100),
                        parallel = FALSE)

leveragePlot(profile = profile, origSDM = spMod,
            leverage_type = "presence_leverage",
            col = "red", plot_type = "points")

charliem2003/sdmProfiling documentation built on June 13, 2022, 4:43 a.m.