Title: | Modeling Species Distributions in Three Dimensions |
Version: | 0.2.3 |
Maintainer: | Hannah L. Owens <hannah.owens@gmail.com> |
Description: | Facilitates modeling species' ecological niches and geographic distributions based on occurrences and environments that have a vertical as well as horizontal component, and projecting models into three-dimensional geographic space. Working in three dimensions is useful in an aquatic context when the organisms one wishes to model can be found across a wide range of depths in the water column. The package also contains functions to automatically generate marine training model training regions using machine learning, and interpolate and smooth patchily sampled environmental rasters using thin plate splines. Davis Rabosky AR, Cox CL, Rabosky DL, Title PO, Holmes IA, Feldman A, McGuire JA (2016) <doi:10.1038/ncomms11484>. Nychka D, Furrer R, Paige J, Sain S (2021) <doi:10.5065/D6W957CT>. Pateiro-Lopez B, Rodriguez-Casal A (2022) https://CRAN.R-project.org/package=alphahull. |
License: | GPL-3 |
URL: | https://hannahlowens.github.io/voluModel/ |
BugReports: | https://github.com/hannahlowens/voluModel/issues |
Encoding: | UTF-8 |
Depends: | R (≥ 4.0.0) |
Imports: | dplyr, fields, ggplot2, ggtext, grDevices, methods, metR, modEvA, rangeBuilder (≥ 2.0), rnaturalearth, terra, viridisLite, sf |
Suggests: | testthat (≥ 3.0.0), nlme, knitr, covr, gridExtra, lattice, rmarkdown, rnaturalearthdata, tibble |
VignetteBuilder: | knitr |
RoxygenNote: | 7.3.2 |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-07-18 15:55:56 UTC; HannahOwens |
Author: | Hannah L. Owens |
Repository: | CRAN |
Date/Publication: | 2025-07-18 23:00:02 UTC |
Calculate MESS
Description
Calculates multivariate environmental similarity surface based on model calibration and projection data
Usage
MESS3D(calibration, projection)
Arguments
calibration |
A |
projection |
A named |
Details
MESS3D
is a wrapper around MESS
from the modEvA
package. It calculates MESS for each depth layer. Negative values
indicate areas of extrapolation which should be interpreted with
caution (see Elith et al, 2010 in MEE).
Value
A SpatRaster
vector with MESS scores for each
voxel; layer names correspond to layer names of first
SpatRaster
vector in projection
list
.
Note
The calibration dataset should include both presences and background/pseudoabsence points used to calibrate an ecological niche model.
References
Elith J, Kearney M, and Phillips S. 2010. The art of modelling range-shifting species. Methods in Ecology and Evolution, 1, 330-342.
See Also
Examples
library(terra)
library(dplyr)
# Create sample rasterBricks
r1 <- rast(ncol=10, nrow=10)
values(r1) <- 1:100
r2 <- rast(ncol=10, nrow=10)
values(r2) <- c(rep(20, times = 50), rep(60, times = 50))
r3 <- rast(ncol=10, nrow=10)
values(r3) <- 8
envBrick1 <- c(r1, r2, r3)
names(envBrick1) <- c(0, 10, 30)
r1 <- rast(ncol=10, nrow=10)
values(r1) <- 100:1
r2 <- rast(ncol=10, nrow=10)
values(r2) <- c(rep(10, times = 50), rep(20, times = 50))
r3 <- rast(ncol=10, nrow=10)
values(r3) <- c(rep(c(10,20,30,25), times = 25))
envBrick2 <- c(r1, r2, r3)
names(envBrick2) <- c(0, 10, 30)
rastList <- list("temperature" = envBrick1, "salinity" = envBrick2)
# Create test reference set
set.seed(0)
longitude <- sample(ext(envBrick1)[1]:ext(envBrick1)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(envBrick1)[3]:ext(envBrick1)[4],
size = 10, replace = FALSE)
set.seed(0)
depth <- sample(0:35, size = 10, replace = TRUE)
occurrences <- as.data.frame(cbind(longitude,latitude,depth))
# Calibration
calibration <- lapply(rastList, FUN = function(x) xyzSample(occurrences, x)) %>% bind_rows
# Run the function
messStack <- MESS3D(calibration = calibration, projection = rastList)
plot(messStack)
Are Colors
Description
Checks to see if a given vector can be interpreted by R as a color or colors
Usage
areColors(col)
Arguments
col |
A vector of anything to be interpreted by |
Value
A logical vector stating whether inputs can be interpreted as colors.
Examples
areColors(col = c("red", "prairie_chicken", 2))
Blend Colors
Description
Generates a blended color from two transparent colors
Usage
blendColor(col1 = "#1b9e777F", col2 = "#7570b37F")
Arguments
col1 |
Anything that can be interpreted by |
col2 |
Anything that can be interpreted by |
Value
A character
string with hex color, including
adjustment for transparency.
Examples
blendColor(col1 = "#1B9E777F", col2 = "#7570B37F")
Bottom raster generation
Description
Samples deepest depth values from a
SpatVector
data frame and generates a SpatRaster
.
Usage
bottomRaster(rawPointData)
Arguments
rawPointData |
A |
Details
rawPointData
is a SpatVector
object that
contains measurements of a single environmental variable (e.g.
salinity, temperature, etc.) with x, y, and z coordinates. The
measurements in the data.frame
should be organized so that each
column is a depth slice, increasing in depth from left to right. The
function was designed around the oceanographic data shapefiles supplied
by the World Ocean Atlas
(https://www.ncei.noaa.gov/access/world-ocean-atlas-2018/).
The function selects the "deepest" (rightmost) measurement at each
x, y coordinate pair that contains data. These measurements are then
rasterized at the resolution and extent of the x,y coordinates, under
the assumption that x and y intervals are equal and represent the center
of a cell.
Value
A SpatRaster
designed to approximate sea bottom
measurements for modeling species' distributions and/or niches.
Examples
library(terra)
# Create point grid
coords <- data.frame(x = rep(seq(1:5), times = 5),
y = unlist(lapply(1:5, FUN = function(x) {
rep(x, times = 5)})))
# Create data and add NAs to simulate uneven bottom depths
dd <- data.frame(SURFACE = 1:25,
d5M = 6:30,
d10M = 11:35,
d25M = 16:40)
dd$d25M[c(1:5, 18:25)] <- NA
dd$d10M[c(3:5, 21:23)] <- NA
dd$d5M[c(4, 22)] <- NA
dd[,c("x","y")] <- coords
# Create SpatialPointsDataFrame
sp <- vect(dd, geom = c("x", "y"))
# Here's the function
result <- bottomRaster(rawPointData = sp)
plot(result)
Center Point Raster Template
Description
Creates a SpatRaster
template from a
SpatVector
point object in which the raster cells
are centered on the vector points.
Usage
centerPointRasterTemplate(rawPointData)
Arguments
rawPointData |
A |
Details
rawPointData
is a SpatVector
object that
contains x and y coordinates.
Value
An empty SpatRaster
designed to serve as a template for
rasterizing SpatVector
objects.
See Also
Examples
library(terra)
# Create point grid
coords <- data.frame(x = rep(seq(1:5), times = 5),
y = unlist(lapply(1:5, FUN = function(x) {
rep(x, times = 5)})))
# Create data and add NAs to simulate uneven bottom depths
dd <- data.frame(SURFACE = 1:25,
d5M = 6:30,
d10M = 11:35,
d25M = 16:40)
dd$d25M[c(1:5, 18:25)] <- NA
dd$d10M[c(3:5, 21:23)] <- NA
dd$d5M[c(4, 22)] <- NA
dd[,c("x","y")] <- coords
# Create SpatialPointsDataFrame
sp <- vect(dd, geom = c("x", "y"))
# Here's the function
template <- centerPointRasterTemplate(rawPointData = sp)
class(template)
Column Parsing
Description
Parses column names from input occurrence
data.frame
for more seamless function
Usage
columnParse(occs, wDepth = FALSE)
Arguments
occs |
A |
wDepth |
Logical; flags whether a depth column should also be sought. |
Details
This is an internal function to return the putative indices for latitude and longitude or x and y coordinates of occurrences to allow for code that is more robust to very common user error
Value
A list
of length 2 with indices of the x and y
columns, respectively, followed by a message with a plain
text report of which columns were interpreted as x and y.
Examples
library(terra)
# Create sample raster
r <- rast(ncol=10, nrow=10)
values(r) <- 1:100
# Create test occurrences
set.seed(0)
longitude <- sample(ext(r)[1]:ext(r)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r)[3]:ext(r)[4],
size = 10, replace = FALSE)
set.seed(0)
depth <- sample(0:35, size = 10, replace = TRUE)
occurrences <- as.data.frame(cbind(longitude,latitude,depth))
# Here's the function
result <- columnParse(occs = occurrences[,1:2],
wDepth = FALSE)
result <- columnParse(occs = occurrences,
wDepth = TRUE)
Diversity stack
Description
Takes list of rasters of species distributions (interpreted as 1 = presence, 0 = absence), which do not have to have the same extents, and stack them to create an estimate of species richness that matches the extent and resolution of a template.
Usage
diversityStack(rasterList, template)
Arguments
rasterList |
A |
template |
A |
Value
A SpatRaster
Examples
library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:1, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,50))
rastList <- list(rast1, rast2)
result <- diversityStack(rasterList = rastList,
template = rast2)
result
plot(result)
Occurrence downsampling
Description
Reduces number of occurrences to resolution of input raster
Usage
downsample(occs, rasterTemplate, verbose = TRUE)
Arguments
occs |
A |
rasterTemplate |
A |
verbose |
|
Value
A data.frame
with two columns named "longitude"
and "latitude" or with names that were used when coercing
input data into this format.
Examples
library(terra)
# Create sample raster
r <- rast(ncol=10, nrow=10)
values(r) <- 1:100
# Create test occurrences
set.seed(0)
longitude <- sample(ext(r)[1]:ext(r)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r)[3]:ext(r)[4],
size = 10, replace = FALSE)
occurrences <- as.data.frame(cbind(longitude,latitude))
# Here's the function
result <- downsample(occs = occurrences, rasterTemplate = r)
Interpolate patchily sampled rasters
Description
Uses thin plate spline regression from
fields
package to interpolate missing two-dimensional
raster values.
Usage
interpolateRaster(inputRaster, fast = FALSE, ...)
Arguments
inputRaster |
An object of class |
fast |
A logical operator. Setting to |
... |
For any additional arguments passed to |
Details
Missing data values from original raster
are replaced with interpolated values. User has the
option of choosing fastTps
to speed calculation,
but be advised that this is only an approximation
of a true thin plate spline.
Value
An object of class raster
See Also
Examples
library(terra)
library(fields)
# Create sample raster
r <- rast(ncol=50, nrow=50)
values(r) <- 1:2500
# Introduce a "hole"
values(r)[c(117:127, 167:177, 500:550)] <- NA
plot(r)
# Patch hole with interpolateRaster
interpolatedRaster <- interpolateRaster(r)
plot(interpolatedRaster)
fastInterp <- interpolateRaster(r, fast = TRUE, aRange = 3.0)
plot(fastInterp)
2D background sampling
Description
Samples in 2D at resolution of raster
Usage
mSampling2D(occs, rasterTemplate, mShp, verbose = TRUE)
Arguments
occs |
A dataframe with at least two columns named "longitude" and "latitude", or that can be coerced into this format. |
rasterTemplate |
A |
mShp |
A shapefile defining the area from which background points should be sampled. |
verbose |
|
Details
This function is designed to sample background points
for distributional modeling in two dimensions. The returned
data.frame
contains all points from across the designated
background. It is up to the user to determine how to
appropriately sample from those background points.
Value
A data.frame
with 2D coordinates of points
for background sampling.
Examples
library(terra)
# Create sample raster
r <- rast(ncol=10, nrow=10)
values(r) <- 1:100
# Create test occurrences
set.seed(0)
longitude <- sample(ext(r)[1]:ext(r)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r)[3]:ext(r)[4],
size = 10, replace = FALSE)
occurrences <- data.frame(longitude,latitude)
# Generate background sampling buffer
buffPts <- vect(occurrences,
c("longitude", "latitude"))
crs(buffPts) <- crs(r)
mShp <- aggregate(buffer(buffPts, width = 1000000))
# Here's the function
result <- mSampling2D(occs = occurrences, rasterTemplate = r, mShp = mShp)
3D background sampling
Description
Samples XYZ coordinates from a shapefile from maximum to minimum occurrence depth at XYZ resolution of envBrick.
Usage
mSampling3D(occs, envBrick, mShp, depthLimit = "all", verbose = TRUE)
Arguments
occs |
A |
envBrick |
A |
mShp |
A shapefile defining the area from which background points should be sampled. |
depthLimit |
An argument controlling the depth
extent of sampling. Refer to |
verbose |
|
Details
This function is designed to sample background points for
distributional modeling in three dimensions. If a voxel (3D pixel)
in the SpatRaster
vector intersects with an occurrence from
occs
, it is removed. Note that this function returns points
representing every voxel in the background area within the
specified depth range. It is up to the user to downsample from
these data as necessary, depending on the model type being used.
depthLimit
argument options:
-
occs
Samples background from the full depth extent ofoccs
. -
all
Samples background from the full depth extent ofenvBrick
. A
vector
of length 2 with maximum and minimum depth values from which to sample.
Value
A data.frame
with 3D coordinates of points for background
sampling.
Examples
library(terra)
# Create test raster
r1 <- rast(ncol=10, nrow=10)
values(r1) <- 1:100
r2 <- rast(ncol=10, nrow=10)
values(r2) <- c(rep(20, times = 50), rep(60, times = 50))
r3 <- rast(ncol=10, nrow=10)
values(r3) <- 8
envBrick <- c(r1, r2, r3)
names(envBrick) <- c(0, 10, 30)
# Create test occurrences
set.seed(0)
longitude <- sample(ext(envBrick)[1]:ext(envBrick)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(envBrick)[3]:ext(envBrick)[4],
size = 10, replace = FALSE)
set.seed(0)
depth <- sample(0:35, size = 10, replace = TRUE)
occurrences <- data.frame(longitude,latitude,depth)
# Generate background sampling buffer
buffPts <- vect(occurrences,
c("longitude", "latitude"))
crs(buffPts) <- crs(envBrick)
mShp <- aggregate(buffer(buffPts, width = 1000000))
# Here's the function
occSample3d <- mSampling3D(occs = occurrences,
envBrick = envBrick,
mShp = mShp,
depthLimit = "occs")
Marine background shapefile generation
Description
Automatically generates background shapefiles for sampling pseudoabsences and/or background points for niche modeling or species distribution modeling. Delineating background sampling regions can be one of the trickiest parts of generating a good model. Automatically generated background shapefiles should be inspected carefully prior to model use.
Useful references, among others:
Barve N, Barve V, Jiménez-Valverde A, Lira-Noriega A, Maher SP, Peterson AT, Soberón J, Villalobos F. 2011. The crucial role of the accessible area in ecological niche modeling and species distribution modeling. Ecological modelling 222:1810-9.
Merow, C, Smith MJ, Silander JA. 2013. A practical guide to MaxEnt for modeling species’ distributions: what it does, and why inputs and settings matter." Ecography 36: 1058-69.
Murphy SJ. 2021. Sampling units derived from geopolitical boundaries bias biodiversity analyses. Global Ecology and Biogeography 30: 1876-88.
Usage
marineBackground(occs, clipToOcean = TRUE, verbose = TRUE, ...)
Arguments
occs |
A |
clipToOcean |
|
verbose |
|
... |
Additional optional arguments to pass to
|
Details
The meat of this function is a special-case wrapper
around getDynamicAlphaHull()
from the rangeBuilder
package.
The function documented here is especially useful in cases where
one wants to automatically generate training regions that overlap
the international date line. Regions that exceed the line are cut
and pasted into the appropriate hemisphere instead of being
deleted.
If the argument buff
is not supplied, a buffer is
calculated by taking the mean between the 10th and 90th percentile
of horizontal distances between occurrence points.
If getDynamicAlphaHull()
cannot satisfy the provided conditions,
the occurrences are buffered and then a minimum convex hull is
drawn around the buffer polygons.
Value
A SpatVector
See Also
Examples
library(terra)
# Create sample raster
r <- rast(ncol=10, nrow=10)
values(r) <- 1:100
# Create test occurrences
set.seed(0)
longitude <- sample(-50:50,
size = 20, replace = FALSE)
set.seed(0)
latitude <- sample(-30:30,
size = 20, replace = FALSE)
occurrences <- as.data.frame(cbind(longitude,latitude))
# Here's the function
result <- marineBackground(occs = occurrences, buff = 100000,
fraction = .9, partCount = 2, clipToOcean = FALSE)
Single raster plot
Description
A convenient wrapper around ggplot
to generate a formatted plot of a single raster.
Usage
oneRasterPlot(
rast,
land = NA,
landCol = "black",
scaleRange = NA,
graticule = TRUE,
title = "A Raster",
verbose = TRUE,
...
)
Arguments
rast |
A single |
land |
An optional coastline polygon shapefile
of types |
landCol |
Color for land on map. |
scaleRange |
Optional numeric vector containing
maximum and minimum values for color scale. Helpful
when making multiple plots for comparison. Defaults
to minimum and maximum of input |
graticule |
|
title |
A title for the plot. |
verbose |
|
... |
Additional optional arguments to pass to
|
Value
A plot of mapping the values of the input raster layer
See Also
Examples
library(terra)
rast <- rast(ncol=10, nrow=10)
values(rast) <- seq(0,99, 1)
oneRasterPlot(rast = rast)
Plotting 3D model in 2D
Description
This script plots a semitransparent layer of suitable habitat for each depth layer. The redder the color, the shallower the layer, the bluer, the deeper. The more saturated the color, the more layers with suitable habitat.
Usage
plotLayers(
rast,
land = NA,
landCol = "black",
title = NULL,
graticule = TRUE,
...
)
Arguments
rast |
A |
land |
An optional coastline polygon shapefile
of types |
landCol |
Color for land on map. |
title |
A title for the plot. If not title is
supplied, the title "Suitability from (MINIMUM
DEPTH) to (MAXIMUM DEPTH)" is inferred from
names of |
graticule |
Do you want a grid of lon/lat lines? |
... |
Additional optional arguments. |
Value
A plot of class recordedplot
Note
Only include the depth layers that you actually want to plot.
See Also
Examples
library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:1, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,50))
rast3 <- rast(ncol=10, nrow=10)
values(rast3) <- rep(c(1,0,0,1), 25)
distBrick <- c(rast1, rast2, rast3)
plotLayers(distBrick)
Comparative point mapping
Description
A convenient wrapper around ggplot
to generate formatted plots comparing two sets of
occurrence point plots.
Usage
pointCompMap(
occs1,
occs2,
spName,
land = NA,
occs1Col = "#bd0026",
occs2Col = "#fd8d3c",
agreeCol = "black",
occs1Name = "Set 1",
occs2Name = "Set 2",
landCol = "gray",
waterCol = "steelblue",
ptSize = 1,
verbose = TRUE,
...
)
Arguments
occs1 |
A |
occs2 |
A |
spName |
A character string with the species name to be used in the plot title. |
land |
An optional coastline polygon shapefile
of types |
occs1Col |
Color for occurrence points on map |
occs2Col |
Color for occurrence points on map |
agreeCol |
Color for occurrence points shared
between |
occs1Name |
An optional name for the first set
of occurrences, which will be color-coded to
|
occs2Name |
An optional name for the first set
of occurrences, which will be color-coded to
|
landCol |
Color for land on map |
waterCol |
Color for water on map |
ptSize |
|
verbose |
|
... |
Additional optional arguments to pass to
|
Value
A ggplot
plot object.
Note
The x and y column names of occs1
and occs2
must match.
See Also
Examples
set.seed(5)
occs <- data.frame(cbind(decimalLatitude = sample(seq(7,35), 24),
decimalLongitude = sample(seq(-97, -70), 24)))
set.seed(0)
occs1 <- occs[sample(1:nrow(occs),
size = 12, replace = FALSE),]
set.seed(10)
occs2 <- occs[sample(1:nrow(occs),
size = 12, replace = FALSE),]
pointCompMap(occs1 = occs1, occs2 = occs2,
occs1Col = "red", occs2Col = "orange",
agreeCol = "purple",
occs1Name = "2D",
occs2Name = "3D",
waterCol = "steelblue",
spName = "Steindachneria argentea",
ptSize = 2,
verbose = FALSE)
Point mapping
Description
A convenient wrapper around ggplot to generate formatted occurrence point plots.
Usage
pointMap(
occs,
spName,
land = NA,
ptCol = "#bd0026",
landCol = "gray",
waterCol = "steelblue",
ptSize = 1,
verbose = TRUE,
...
)
Arguments
occs |
A |
spName |
A character string with the species name to be used in the plot title. |
land |
An optional coastline polygon shapefile
of types |
ptCol |
Color for occurrence points on map |
landCol |
Color for land on map |
waterCol |
Color for water on map |
ptSize |
|
verbose |
|
... |
Additional optional arguments to pass to
|
Value
A ggplot
plot object.
See Also
Examples
occs <- read.csv(system.file("extdata/Steindachneria_argentea.csv",
package='voluModel'))
spName <- "Steindachneria argentea"
pointMap(occs = occs, spName = spName,
land = rnaturalearth::ne_countries(scale = "small",
returnclass = "sf")[1])
Comparative raster mapping
Description
A convenient wrapper around terra::plot
to generate formatted plots comparing two rasters.
This is used in the context of voluModel to
overlay semi-transparent distributions (coded as 1)
in two different RasterLayers
.
Usage
rasterComp(
rast1 = NULL,
rast2 = NULL,
col1 = "#1b9e777F",
col2 = "#7570b37F",
rast1Name = "Set 1",
rast2Name = "Set 2",
land = NA,
landCol = "black",
title = "A Raster Comparison",
graticule = TRUE,
...
)
Arguments
rast1 |
A single |
rast2 |
A single |
col1 |
Color for |
col2 |
Color for |
rast1Name |
An optional name for the first set
of occurrences, which will be color-coded to
|
rast2Name |
An optional name for the first set
of occurrences, which will be color-coded to
|
land |
An optional coastline polygon shapefile
of types |
landCol |
Color for land on map. |
title |
A title for the plot. |
graticule |
Do you want a grid of lon/lat lines? |
... |
Additional optional arguments to pass to
|
Value
A plot of class recordedplot
overlaying mapped,
semitransparent extents of the input rasters
Note
The extents of rast1
and rast2
must match.
See Also
Examples
library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:1, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,50))
rasterComp(rast1 = rast1, rast2 = rast2)
Smooth rasters
Description
Uses thin plate spline regression from
fields
package to smooth raster values.
Usage
smoothRaster(inputRaster, fast = FALSE, ...)
Arguments
inputRaster |
An object of class |
fast |
A logical operator. Setting to |
... |
For any additional arguments passed to |
Details
Original raster is smoothed using a thin
plate spline. This may be desirable in cases where
the user has a reasonable expectation of spatial autocorrelation,
but observes putative measurement errors in a raster. The user has
the option of choosing fastTps
to speed calculation,
but be advised that this is only an approximation
of a true thin plate spline.
Value
An object of class SpatRaster
See Also
Examples
library(terra)
library(fields)
# Create sample raster
r <- rast(ncol=100, nrow=100)
values(r) <- 1:10000
# Introduce a "bubble"
values(r)[720:725] <- 9999
plot(r)
# Smooth bubble with smoothRaster
fastSmooth <- smoothRaster(r, fast = TRUE, aRange = 10.0)
plot(fastSmooth)
Test Intersection
Description
Tests whether two rasters overlap. Used in
\code{\link[voluModel:diversityStack]{diversityStack}}
function to verify all rasters in list overlap with the
template raster.
Usage
testIntersection(a, b)
Arguments
a |
The first |
b |
The second |
Value
A logical vector stating whether the two inputs overlap
Examples
library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:1, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,50))
testIntersection(rast1, rast2)
rast1 <- crop(rast1, ext(10, 20, 30, 40))
rast2 <- crop(rast2, ext(-20, -10, -40, -30))
testIntersection(rast1, rast2)
Plot vertical sample
Description
Plots cell values along a vertical transect
Usage
transectPlot(
rast = NULL,
sampleAxis = "lon",
axisValue = NA,
scaleRange = NA,
plotLegend = TRUE,
depthLim = as.numeric(max(names(rast))),
transRange = c(-90, 90),
transTicks = 20,
verbose = FALSE,
...
)
Arguments
rast |
A multilayer |
sampleAxis |
Specifies whether a latitudinal ("lat") or longitudinal ("long") transect is desired. |
axisValue |
Numeric value specifying transect postion. |
scaleRange |
A numeric vector of length 2, specifying the range that should be used for the plot color scale. |
plotLegend |
|
depthLim |
A single vector of class |
transRange |
A |
transTicks |
|
verbose |
|
... |
Additional optional arguments to pass to |
Value
A ggplot
showing a vertical slice through the SpatRaster
.
Note
Only unprojected SpatRaster
files are supported.
Examples
library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:3, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,25), rep(2,25))
rast3 <- rast(ncol=10, nrow=10)
values(rast3) <- rep(c(1,3,2,1), 25)
distBrick <- c(rast1, rast2, rast3)
names(distBrick) <- c(0:2)
transectPlot(distBrick, depthLim = 3)
Transparent Color
Description
Generates transparent colors
Usage
transpColor(color, percent = 50)
Arguments
color |
Anything that can be interpreted by |
percent |
A whole number between 0 and 100 specifying how transparent the color should be. |
Value
A character
string with hex color, including
adjustment for transparency.
Examples
transpColor(color = "red", percent = 50)
Vertical sample
Description
Samples data along a vertical transect
Usage
verticalSample(x = NULL, sampleAxis = "lon", axisValue = NA)
Arguments
x |
A multilayer |
sampleAxis |
Specifies whether a latitudinal ("lat") or longitudinal ("long") transect is desired. |
axisValue |
Numeric value specifying transect postion. |
Value
A data.frame
with values sampled across vertical
transect.
Note
Only unprojected SpatRaster
files are supported.
Sampling from a SpatRaster
vector using 3D coordinates
Description
Gets values at x,y,z occurrences from a given 3D environmental variable brick
Usage
xyzSample(occs, envBrick, verbose = TRUE)
Arguments
occs |
A |
envBrick |
A |
verbose |
|
Details
The SpatRaster
vector object should
have numeric names that correspond with the beginning
depth of a particular depth slice. For example, one
might have three layers, one from 0 to 10m, one from
10 to 30m, and one from 30 to 100m. You would name the
layers in this brick names(envBrick) <- c(0, 10, 30
.
xyzSample
identifies the layer name that is closest
to the depth layer value at a particular X, Y
coordinate, and samples the environmental value at that
3D coordinate.
Value
Vector of environmental values equal in length
to number of rows of input occs
data.frame
.
Examples
library(terra)
# Create test raster
r1 <- rast(ncol=10, nrow=10)
values(r1) <- 1:100
r2 <- rast(ncol=10, nrow=10)
values(r2) <- c(rep(20, times = 50), rep(60, times = 50))
r3 <- rast(ncol=10, nrow=10)
values(r3) <- 8
envBrick <- c(r1, r2, r3)
names(envBrick) <- c(0, 10, 30)
# Create test occurrences
set.seed(0)
longitude <- sample(ext(envBrick)[1]:ext(envBrick)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(envBrick)[3]:ext(envBrick)[4],
size = 10, replace = FALSE)
set.seed(0)
depth <- sample(0:35, size = 10, replace = TRUE)
occurrences <- as.data.frame(cbind(longitude,latitude,depth))
# Test function
occSample3d <- xyzSample(occurrences, envBrick)
# How to use
occurrences$envtValue <- occSample3d