plot_overlap: Plot results of niche overlap analyses

View source: R/plot_overlap.R

plot_overlapR Documentation

Plot results of niche overlap analyses

Description

plot_overlap helps to create two or three dimensional representations of the overlap results obtained with the function ellipsoid_overlap.

Usage

plot_overlap(object, niches = c(1, 2), niche_col = c("blue", "red"),
             data = TRUE, data_col = c("blue", "red"),
             background = FALSE, background_type, proportion = 0.3,
             background_col = viridis::viridis, change_labels = FALSE,
             xlab = "", ylab = "", zlab = "", legend = TRUE)

Arguments

object

overlap_ellipsoid object resulted from using the function ellipsoid_overlap.

niches

(numeric) pair of integer numbers denoting the niches to be plotted. Default = c(1, 2).

niche_col

colors to be used to plot ellipsoids of niches to be compared. Default = c("blue", "red").

data

(logical) whether or not to plot points of species data. Default = TRUE.

data_col

colors to be used to plot data points of niches to be compared. Default = c("blue", "red").

background

(logical) whether or not to plot background points. Default = TRUE.

background_type

(character) type of background to be plotted. Options are: "full", "back_union". See ellipsoid_overlap.

proportion

(numeric) proportion of background to be plotted. Default = 0.3.

background_col

color ramp to be used for coloring background points. Default = viridis::viridis.

change_labels

(logical) whether or not to change axes label. Default = FALSE.

xlab

(character) lable of x axis. Default = "".

ylab

(character) lable of y axis. Default = "".

zlab

(character) lable of z axis. Default = "".

legend

(logical) whether or not to add a simple legend. Default = TRUE.

Value

A plot of the niches to be compared in environmental space.

Examples

# Preparing example
# reading data
occurrences <- read.csv(system.file("extdata", "occurrences.csv",
                                    package = "ellipsenm"))

# raster layers of environmental data
vars <- raster::stack(list.files(system.file("extdata", package = "ellipsenm"),
                                 pattern = "bio", full.names = TRUE))

# preparing data
vext <- raster::extent(vars)
ext1 <- raster::extent(vext[1], (mean(vext[1:2]) + 0.2), vext[3:4])
ext2 <- raster::extent((mean(vext[1:2]) + 0.2), vext[2], vext[3:4])

# croping variables and splitting occurrences
vars1 <- raster::stack(raster::crop(vars, ext1))
vars2 <- raster::stack(raster::crop(vars, ext2))

occurrences1 <- occurrences[occurrences$longitude < (mean(vext[1:2]) + 0.2),]
occurrences2 <- occurrences[!occurrences$longitude %in% occurrences1$longitude,]

# preparing overlap objects to perform analyses
niche1 <- overlap_object(occurrences1, species =  "species", longitude = "longitude",
                         latitude = "latitude", method = "covmat", level = 95,
                         variables = vars1)

niche2 <- overlap_object(occurrences2, species =  "species", longitude = "longitude",
                         latitude = "latitude", method = "covmat", level = 95,
                         variables = vars2)

# niche overlap analysis
overlap <- ellipsoid_overlap(niche1, niche2)

# Now the plots
# plotting only ellipsoids
plot_overlap(overlap)

# plotting ellispodis and background for full overlap
plot_overlap(overlap, background = TRUE, proportion = 0.6, background_type = "full")

# plotting ellispodis and background for overlap based on accessible environments
plot_overlap(overlap, background = TRUE,  proportion = 1, background_type = "back_union")

marlonecobos/ellipsenm documentation built on Oct. 18, 2023, 8:09 a.m.