Learn R Programming

phyloregion (version 1.0.2)

raster2comm: Convert raw input distribution data to community

Description

The functions points2comm, polys2comm, raster2comm provide convenient interfaces to convert raw distribution data often available as point records, extent-of-occurrence polygons and raster layers, respectively, to a community composition data frame at varying spatial grains and extents for downstream analyses.

Usage

raster2comm(files)

polys2comm(dat, res = 1, shp.grids = NULL, species = "species", ...)

points2comm( dat, mask = NULL, res = 1, lon = "decimallongitude", lat = "decimallatitude", species = "species", shp.grids = NULL, ... )

Arguments

files

list of raster layer objects with the same spatial extent and resolution.

dat

layers of merged maps corresponding to species ranges 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)

res

the grain size of the grid cells in decimal degrees (default).

shp.grids

if specified, the polygon shapefile of grid cells with a column labeled “grids”.

species

a character string. The column with the species or taxon name. Default = “species”.

Further arguments passed to or from other methods.

mask

Only applicable to points2comm. If supplied, a polygon shapefile covering the boundary of the survey region.

lon

character with the column name of the longitude.

lat

character with the column name of the latitude.

Value

  • comm_dat: community data frame

  • poly_shp: shapefile of grid cells with the values per cell.

See Also

mapproject for conversion of latitude and longitude into projected coordinates system.

Examples

Run this code
# NOT RUN {
fdir <- system.file("NGAplants", package="phyloregion")
files <- file.path(fdir, dir(fdir))
raster2comm(files)
# }
# NOT RUN {
# }
# NOT RUN {
s <- readRDS(system.file("nigeria/nigeria.rds", package="phyloregion"))
sp <- random_species(100, species=5, shp=s)
polys2comm(dat = sp, species = "species")
# }
# NOT RUN {
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")
head(pt[[1]])
# }

Run the code above in your browser using DataLab