Plots the 2D boundary of a nicheR_ellipsoid object in environmental
space for a chosen pair of dimensions. Optionally overlays background points
or a prediction surface colored by a continuous variable (e.g., suitability).
Use add_data and add_ellipsoid to layer additional
data onto the plot after calling this function.
Usage
plot_ellipsoid(
object,
background = NULL,
prediction = NULL,
dim = c(1, 2),
col_layer = NULL,
pal = hcl.colors(100, palette = "Viridis"),
rev_pal = FALSE,
bg_sample = NULL,
lty = 1,
lwd = 1,
col_ell = "#000000",
col_bg = "#8A8A8A",
pch = 1,
alpha_bg = 1,
alpha_ell = 1,
cex_ell = 1,
cex_bg = 1,
fixed_lims = NULL,
...
)Arguments
- object
A
nicheR_ellipsoidobject containing at leastcentroid,cov_matrix,chi2_cutoff, andvar_names.- background
Optional data frame or matrix of background points to plot behind the ellipsoid. Rows are observations, columns are environmental variables. If provided,
predictionis ignored.- prediction
Optional data frame or matrix of prediction values to plot. Used when
backgroundisNULL. Can be colored by a continuous variable usingcol_layer.- dim
Integer vector of length 2. Indices of the two dimensions to plot. Default is
c(1, 2).- col_layer
Character or
NULL. Name of a column inpredictionto use for coloring points by a continuous variable. IfNULL(default), all prediction points are drawn withcol_bg.- pal
A color palette function or character vector used when
col_layeris provided. Default ishcl.colors(100, palette = "Viridis").- rev_pal
Logical. If
TRUE, reverses the color palette. Default isFALSE.- bg_sample
Integer or
NULL. If provided and the number of background or prediction rows exceeds this value, a random subsample of this size is drawn before plotting. Useful for large data frames. Default isNULL(plot all points).- lty
Integer. Line type for the ellipsoid boundary. Default is
1(solid).- lwd
Numeric. Line width for the ellipsoid boundary. Default is
1.- col_ell
Character. Color of the ellipsoid boundary line. Default is
"#000000"(black).- col_bg
Character. Color of background or prediction points when
col_layerisNULL. Default is"#8A8A8A"(grey).- pch
Integer or character. Point symbol for background or prediction points. Default is
1.- alpha_bg
Numeric in
[0, 1]. Transparency of background or prediction points. Default is1(fully opaque).- alpha_ell
Numeric in
[0, 1]. Transparency of the ellipsoid boundary line. Default is1(fully opaque).- cex_ell
Numeric. Size scaling for the ellipsoid boundary line. Default is
1.- cex_bg
Numeric. Size scaling for background or prediction points. Default is
1.- fixed_lims
A named list with elements
xlimandylim, each a numeric vector of length 2. When provided, overrides the limits computed bysafe_lims(). Intended for use byplot_ellipsoid_pairsto enforce consistent axis scales across panels, but can also be set manually by the user. Default isNULL(limits computed from data).- ...
Additional graphical parameters passed to
plot.
Details
The function has three display modes depending on what is provided:
Background only (
backgroundis notNULL): plots background points incol_bgwith the ellipsoid boundary overlaid.Prediction surface (
backgroundisNULL,predictionis notNULL): plots prediction points, optionally colored bycol_layerusing values mapped ontopal. Whencol_layeris provided, points outside the ellipsoid (zero orNAincol_layer, as produced by truncated prediction types) are drawn incol_bgbehind the colored interior points. Axis limits are computed from the fullpredictionextent so the view is never collapsed to the ellipsoid interior.Ellipsoid only (both
NULL): plots the ellipsoid boundary alone with no background.
See also
add_data to overlay occurrence points,
add_ellipsoid to overlay additional ellipsoid boundaries,
plot_ellipsoid_pairs for pairwise plots of all dimensions.