The functions points2comm
, polys2comm
, raster2comm
provide convenient interfaces to convert raw distribution data often
available as point records, polygons and raster layers,
respectively, to a community composition data frame at varying spatial grains
and extents for downstream analyses.
raster2comm(files)polys2comm(dat, res = 1, species = "species", shp.grids = NULL, ...)
points2comm(
dat,
mask = NULL,
res = 1,
lon = "decimallongitude",
lat = "decimallatitude",
species = "species",
shp.grids = NULL,
...
)
Each of these functions generate a list of two objects as follows:
comm_dat: (sparse) community matrix
poly_shp: shapefile of grid cells with the values per cell.
list of raster layer objects with the same spatial extent and resolution.
layers of merged maps corresponding to species polygons for
polys2comm
; or point occurrence data frame for points2comm
,
with at least three columns:
Column 1: species
(listing the taxon names)
Column 2: decimallongitude
(corresponding to decimal longitude)
Column 3: decimallatitude
(corresponding to decimal latitude)
the grain size of the grid cells in decimal degrees (default).
a character string. The column with the species or taxon name. Default = “species”.
if specified, the polygon shapefile of grid cells with a column labeled “grids”.
Further arguments passed to or from other methods.
Only applicable to points2comm
. If supplied, a polygon
shapefile covering the boundary of the survey region.
character with the column name of the longitude.
character with the column name of the latitude.
mapproject
for conversion of
latitude and longitude into projected coordinates system.
long2sparse
for conversion of community data.
# \donttest{
fdir <- system.file("NGAplants", package="phyloregion")
files <- file.path(fdir, dir(fdir))
ras <- raster2comm(files) # Note, this function generates
# a list of two objects
head(ras[[1]])
# }
# \donttest{
s <- readRDS(system.file("nigeria/nigeria.rds", package="phyloregion"))
sp <- random_species(100, species=5, shp=s)
pol <- polys2comm(dat = sp, species = "species")
head(pol[[1]])
# }
s <- readRDS(system.file("nigeria/nigeria.rds", package = "phyloregion"))
set.seed(1)
m <- data.frame(sp::spsample(s, 10000, type = "nonaligned"))
names(m) <- c("lon", "lat")
species <- paste0("sp", sample(1:1000))
m$taxon <- sample(species, size = nrow(m), replace = TRUE)
pt <- points2comm(dat = m, mask = s, res = 0.5, lon = "lon", lat = "lat",
species = "taxon") # Note, this generates a list of two objects
head(pt[[1]])
Run the code above in your browser using DataLab