profilePlot: Make a 'profile plot' - the Diff0 values plotted against...

View source: R/profilePlot.R

profilePlotR Documentation

Make a 'profile plot' - the Diff0 values plotted against Diff1 values outputted from SDM profiling for unsampled cells

Description

Make a 'profile plot' - the Diff0 values plotted against Diff1 values outputted from SDM profiling for unsampled cells

Usage

profilePlot(
  profile,
  points = TRUE,
  contours = FALSE,
  density = FALSE,
  save_plot = FALSE
)

Arguments

profile

the output from sdmProfiling

points

TRUE (default) or FALSE whether to plot the individual points

contours

TRUE or FALSE (default) whether to plot contours of point density

density

TRUE or FALSE (default) whether to plot a raster of point density (blue to red)

save_plot

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

Value

Automatically generates a profile plot.

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

Author(s)

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

Examples

set.seed(9999)
envSet <- create_env_nsets(cellDims = c(100, 100),
                           sets     = c(4, 4, 3, 1),
                           model    = "Sph",
                           psill    = 1.5,
                           dep1     = 1,
                           rangeFun = function() exp(runif(1, 1, 6)),
                           propSamp = 0.25)

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

### an initial 'sample' of the species (assuming perfect detection)
sampPts <- data.frame(sampleRandom(sp$presence, 50, 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)

### a random set of 500 points to profile
unsampPts <- data.frame(x = runif(500, 1, 100), y = runif(500, 1, 100))
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)

### simple plot of points
profilePlot(profile, points = TRUE, contours = FALSE, density = FALSE)

### also include a background of point density and contours
profilePlot(profile, points = TRUE, contours = TRUE, density = TRUE)


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