View source: R/lets_presab_grid_points.R
| lets.presab.grid.points | R Documentation |
Convert species' occurrences points into a presence-absence matrix based on a grid in shapefile format.
lets.presab.grid.points(
xy,
species,
grid,
sample.unit,
remove.sp = TRUE,
abundance = TRUE
)
xy |
A matrix with geographic coordinates of species occurrences, first column is the longitude (or x), and the second latitude (or y). |
species |
Character vector with species names, in the same order as the coordinates. |
grid |
Object of class SpatVector (see function
|
sample.unit |
Object of class |
remove.sp |
Logical, if |
abundance |
Logical. If TRUE, the resulting matrix will display number of occurrences per species in each cell. If FALSE, the resulting matrix will show presence-absence values. |
This function is an alternative way to create a presence absence matrix when users already have their own grid.
The result is a list containing two objects:
(I) A matrix the species presence (1) and absence (0) values per sample unit.
(II) The original grid.
Bruno Vilela & Fabricio Villalobos
lets.presab.points
lets.presab.grid
## Not run:
# Species polygons
data("wrld_simpl")
# Grid
crs = "+proj=longlat +datum=WGS84 +no_defs"
sp.r <- terra::as.polygons(terra::rast(
resol = 5,
crs = crs,
xmin = -93,
xmax = -29,
ymin = -57,
ymax = 15
))
sp.r$ID <- 1:length(sp.r)
# Occurrence Points
N = 20
species <- c(rep("sp1", N), rep("sp2", N),
rep("sp3", N), rep("sp4", N))
x <- runif(N * 4, min = -69, max = -51)
y <- runif(N * 4, min = -23, max = -4)
xy <- cbind(x, y)
# PAM
resu <- lets.presab.grid.points(xy, species, sp.r, "ID", abundance = FALSE)
# Plot
rich_plus1 <- rowSums(resu$PAM[, -1, drop = FALSE]) + 1
colfunc <- colorRampPalette(c("#fff5f0", "#fb6a4a", "#67000d"))
colors <- c("white", colfunc(max(rich_plus1)))
occs <- terra::vect(xy, crs = crs)
plot(resu$grid, border = "gray40",
col = colors[rich_plus1])
plot(sf::st_geometry(wrld_simpl), add = TRUE)
plot(occs, cex = 0.5, col = rep(1:4, each = N), add = T)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.