Visualizing the environmental space of genetically defined populations
Source:R/envplot.R
envplot.RdThis function visualizes the environmental variability across a defined geographic area and within the estimated genetically defined populations of a species. After estimating an ancestry probability surface using popmaps(), a user would generate random background points for each genetically defined population using bg_pop_pts(). In addition, points representing the focal species (i.e., the 'focal points,' such as may be downloaded from a herbarium or biodiversity database) are assigned to the estimated populations using ptsNpop(). Finally, a principal components analysis (PCA) performed using popmap_pca() summarizes environmental variation across user-supplied environmental layers. After extracting PC data for the background and focal points, data can be visualized in PC space or as box plots. Data may be visualized for any pair of PC axes resulting from the PCA.
Usage
envplot(
bg_env = "",
pop_env = "",
pt_env = NULL,
input_raster = "",
axis1 = 1,
axis2 = 2,
plot_type = c("env", "box")
)Arguments
- bg_env
An R object resulting from extracting PC data for spatial points defined by bg_pop_pts(). After PC data are extracted by genetically defined population (see example below), data per axis are combined into a list, with each element representing a matrix of PC data for the background points falling within each genetically defined population.
- pop_env
An R object resulting from extracting PC data for spatial points defined by ptsNpop(). After PC data are extracted by genetically defined population (see example below), data per axis are combined into a list, with each element representing a matrix of PC data for the points falling within each genetically defined population.
- pt_env
This parameter is not currently implemented.
- input_raster
An R RasterLayer object defining the geographic extent for the spatial interpolation.
- axis1
This will be the x-axis, or environmental variable 1, in the output from envplot(). Any number from 1 to the number of PC axes (i.e., the number of environmental layers used in the PCA) may be used, though the first few PC axes generally explain the majority of environmental variation across the study area.
- axis2
This will be the y-axis, or environmental variable 2, in the output from envplot().Any number from 1 to the number of PC axes (i.e., the number of environmental layers used in the PCA) may be used, though the first few PC axes generally explain the majority of environmental variation across the study area.
- plot_type
Determines the graphical output that results from executing envplot(). If 'env', the output will be a graph displaying PC space for axis1 x axis2. Points (both background and focal) are colored uniquely by their genetically defined population. Background points are smaller and partially transparent. Focal points are larger and have contour lines that represent the density of points in environmental space. If 'box', the output will contain multiple boxplots showing the range of environmental variation for the focal points according to the genetically defined populations, as well as axis1 and axis2.
References
Massatti R & Winkler DE. (2022) Spatially explicit management of genetic diversity using ancestry probability surfaces. Methods in Ecology and Evolution. http://dx.doi.org/10.1111/2041-210X.13902
Examples
if (FALSE) { # \dontrun{
ex_raster <- raster::aggregate(hija_raster,fact=16) #Cells in embedded raster are aggregated to reduce computation time
pp <- popmaps(input_raster=ex_raster,input_locs=hija_struc,empirical_pt_dist=5,num_sites=15,num_tested=4,popmod=-0.05,threshold=0,surface='G')
bg_pts <- bg_pop_pts(pop_raster_list = pp, input_locs = hija_struc, input_raster = hija_raster, bg_pts=2000)
samp_per_pop <- ptsNpop(pop_raster_list=pp, input_locs=hija_struc, input_raster=hija_raster,sampling_pts=hija_herb)
#This function requires a pathway to a folder containing environmental data layers that are not included in the POPMAPS package.
pca <- popmap_pca(input_raster=hija_raster, bio_dir='./wc2.1_30s_bio/')
xx <- raster::extract(pca,bg_pts[[1]])
xx <- xx[!is.na(xx[,1]),]
yy <- raster::extract(pca,bg_pts[[2]])
yy <- yy[!is.na(yy[,1]),]
zz <- raster::extract(pca,bg_pts[[3]])
zz <- zz[!is.na(zz[,1]),]
bg_env <- list(xx,yy,zz)
pop1_pca <- raster::extract(pca,samp_per_pop[[1]])
pop2_pca <- raster::extract(pca, samp_per_pop[[2]])
pop3_pca <- raster::extract(pca, samp_per_pop[[3]])
pop_env <- list(pop1_pca,pop2_pca,pop3_pca)
envplot(bg_env=bg_env,pop_env=pop_env,input_raster=hija_raster,plot_type='env')
} # }