plot_predict: Visualizations for a predicted ecological niche in geographic...

View source: R/plot_predict.R

plot_predictR Documentation

Visualizations for a predicted ecological niche in geographic space

Description

Create multiple plots of output from the lrren function, specifically for the predicted values of the ecological niche at geographic coordinates.

Usage

plot_predict(
  input,
  plot_cols = c("#8B3A3A", "#CCCCCC", "#0000CD", "#FFFF00"),
  alpha = input$p_critical,
  cref0 = "EPSG:4326",
  cref1 = NULL,
  lower_lrr = NULL,
  upper_lrr = NULL,
  digits = 1,
  ...
)

Arguments

input

An object of class 'list' from the lrren function.

plot_cols

Character string of length four (4) specifying the colors for plotting: 1) presence, 2) neither, 3) absence, and 4) NA values. The default colors in hex are c("#8B3A3A", "#CCCCCC", "#0000CD" "#FFFF00") or c("indianred4", "grey80", "blue3", "yellow").

alpha

Optional, numeric. The two-tailed alpha level for significance threshold (default is the p_critical value imported from input).

cref0

Character. The Coordinate Reference System (CRS) for the x- and y-coordinates in geographic space. The default is WGS84 "EPSG:4326".

cref1

Optional, character. The Coordinate Reference System (CRS) to spatially project the x- and y-coordinates in geographic space.

lower_lrr

Optional, numeric. Lower cut-off value for the log relative risk value in the color key (typically a negative value). The default is no limit, and the color key will include the minimum value of the log relative risk surface.

upper_lrr

Optional, numeric. Upper cut-off value for the log relative risk value in the color key (typically a positive value). The default is no limit, and the color key will include the maximum value of the log relative risk surface.

digits

Optional, integer. The number of significant digits for the color key labels using the round function (default is 1).

...

Arguments passed to image.plot for additional graphical features.

Value

This function produces two plots in a two-dimensional space where the axes are geographic coordinates (e.g., longitude and latitude): 1) predicted log relative risk, and 2) significant p-values.

Examples

if (interactive()) {
  set.seed(1234) # for reproducibility

# Using the 'bei' and 'bei.extra' data within {spatstat.data}

# Covariate data (centered and scaled)
  elev <- spatstat.data::bei.extra[[1]]
  grad <- spatstat.data::bei.extra[[2]]
  elev$v <- scale(elev)
  grad$v <- scale(grad)
  elev_raster <- terra::rast(elev)
  grad_raster <- terra::rast(grad)

# Presence data
  presence <- spatstat.data::bei
  spatstat.geom::marks(presence) <- data.frame("presence" = rep(1, presence$n),
                                          "lon" = presence$x,
                                          "lat" = presence$y)
  spatstat.geom::marks(presence)$elev <- elev[presence]
  spatstat.geom::marks(presence)$grad <- grad[presence]

# (Pseudo-)Absence data
  absence <- spatstat.random::rpoispp(0.008, win = elev)
  spatstat.geom::marks(absence) <- data.frame("presence" = rep(0, absence$n),
                                              "lon" = absence$x,
                                              "lat" = absence$y)
  spatstat.geom::marks(absence)$elev <- elev[absence]
  spatstat.geom::marks(absence)$grad <- grad[absence]

# Combine into readable format
  obs_locs <- spatstat.geom::superimpose(presence, absence, check = FALSE)
  obs_locs <- spatstat.geom::marks(obs_locs)
  obs_locs$id <- seq(1, nrow(obs_locs), 1)
  obs_locs <- obs_locs[ , c(6, 2, 3, 1, 4, 5)]
  
# Prediction Data
  predict_xy <- terra::crds(elev_raster)
  predict_locs <- as.data.frame(predict_xy)
  predict_locs$elev <- terra::extract(elev_raster, predict_xy)[ , 1]
  predict_locs$grad <- terra::extract(grad_raster, predict_xy)[ , 1]

# Run lrren
  test_lrren <- lrren(obs_locs = obs_locs,
                      predict_locs = predict_locs,
                      predict = TRUE)
                      
# Run plot_predict
  plot_predict(input = test_lrren, cref0 = "EPSG:5472")
}


Waller-SUSAN/envi documentation built on Nov. 8, 2024, 12:35 a.m.