plotResponse: Visualise the response of the virtual species to...

View source: R/plotResponse.R

plotResponseR Documentation

Visualise the response of the virtual species to environmental variables

Description

This function plots the relationships between the virtual species and the environmental variables. It requires either the output from generateSpFromFun, generateSpFromPCA, generateRandomSp, or a manually defined set of environmental variables and response functions.

Usage

plotResponse(
  x,
  parameters = NULL,
  approach = NULL,
  rescale = NULL,
  axes.to.plot = NULL,
  no.plot.reset = FALSE,
  rescale.each.response = NULL,
  ...
)

Arguments

x

the output from generateSpFromFun, generateSpFromPCA, generateRandomSp, or a raster layer/stack of environmental variables (see details for the latter).

parameters

in case of manually defined response functions, a list containing the associated parameters. See details.

approach

in case of manually defined response functions, the chosen approach: either "response" for a per-variable response approach, or "pca" for a PCA approach.

rescale

TRUE or FALSE. If TRUE, individual response plots are rescaled between 0 and 1.

axes.to.plot

a vector of 2 values listing the two axes of the PCA to plot. Only useful for a PCA species.

no.plot.reset

TRUE or FALSE. If FALSE, the plot window will be reset to its initial state after the response has been plotted.

rescale.each.response

TRUE or FALSE. If TRUE, the individual responses to each environmental variable are rescaled between 0 and 1.

...

further arguments to be passed to plot. See plot and par.

Details

If you provide the output from generateSpFromFun, generateSpFromPCA or generateRandomSp then the function will automatically make the appropriate plots.

Otherwise, you can provide a raster layer/stack of environmental variables to x and a list of functions to parameters to perform the plot. In that case, you have to specify the approach: "reponse" or "PCA":

  • if approach = "response": Provide to parameters a list exactly as defined in generateSpFromFun:
    list( var1 = list(fun = 'fun1', args = list(arg1 = ..., arg2 = ..., etc.)), var2 = list(fun = 'fun2', args = list(arg1 = ..., arg2 = ..., etc.)))

  • if approach = "PCA": Provide to parameters a list containing the following elements:

    • pca: a dudi.pca object computed with dudi.pca

    • means: a vector containing two numeric values. Will be used to define the means of the gaussian response functions to the axes of the PCA.

    • sds a vector containing two numeric values. Will be used to define the standard deviations of the gaussian response functions to the axes of the PCA.

Author(s)

Boris Leroy leroy.boris@gmail.com

with help from C. N. Meynard, C. Bellard & F. Courchamp

Examples

# Create an example stack with four environmental variables
a <- matrix(rep(dnorm(1:100, 50, sd = 25)), 
            nrow = 100, ncol = 100, byrow = TRUE)
env <- c(rast(a * dnorm(1:100, 50, sd = 25)),
         rast(a * 1:100),
         rast(a * logisticFun(1:100, alpha = 10, beta = 70)),
         rast(t(a)))
names(env) <- c("var1", "var2", "var3", "var4")

# Per-variable response approach:
parameters <- formatFunctions(var1 = c(fun = 'dnorm', mean = 0.00012,
                                       sd = 0.0001),
                              var2 = c(fun = 'linearFun', a = 1, b = 0),
                              var3 = c(fun = 'quadraticFun', a = -20, b = 0.2, 
                                       c = 0),
                              var4 = c(fun = 'logisticFun', alpha = -0.001, 
                                       beta = 0.002))
sp1 <- generateSpFromFun(env, parameters, plot = TRUE)
plotResponse(sp1)

# PCA approach:
sp2 <- generateSpFromPCA(env, plot = FALSE)
par(mfrow = c(1, 1))
plotResponse(sp2)


virtualspecies documentation built on Sept. 27, 2023, 1:06 a.m.