The functions points2comm, polys2comm, rast2comm 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.

rast2comm(files)

polys2comm(dat, res = 0.25, pol.grids = NULL, ...)

points2comm(dat, res = 0.25, pol.grids = NULL, ...)

Arguments

files

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

dat

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)

res

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

pol.grids

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

...

Further arguments passed to or from other methods.

Value

Each of these functions generate a list of two objects as follows:

  • comm_dat: (sparse) community matrix

  • map: vector or raster of grid cells with the values per cell for mapping.

See also

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

Examples

# \donttest{
fdir <- system.file("NGAplants", package="phyloregion")
files <- file.path(fdir, dir(fdir))
ras <- rast2comm(files) # Note, this function generates
     # a list of two objects
head(ras[[1]])
#> 6 x 8 sparse Matrix of class "dgCMatrix"
#>      Chytranthus_gilletii Commelina_ramulosa Cymbopogon_caesius
#> v100                    .                  .                  .
#> v101                    .                  .                  .
#> v102                    .                  .                  .
#> v103                    .                  .                  .
#> v104                    .                  .                  .
#> v105                    .                  .                  .
#>      Dalechampia_ipomoeifolia Grewia_barombiensis Indigofera_berhautiana
#> v100                        1                   .                      .
#> v101                        1                   .                      .
#> v102                        1                   .                      .
#> v103                        1                   .                      .
#> v104                        1                   .                      .
#> v105                        1                   .                      .
#>      Indigofera_erecta Indigofera_oubanguiensis
#> v100                 .                        .
#> v101                 .                        .
#> v102                 .                        .
#> v103                 .                        .
#> v104                 .                        .
#> v105                 .                        .
# }

# \donttest{
require(terra)
s <- vect(system.file("ex/nigeria.json", package="phyloregion"))
sp <- random_species(100, species=5, pol=s)
pol <- polys2comm(dat = sp)
head(pol[[1]])
#> 6 x 5 sparse Matrix of class "dgCMatrix"
#>       species1 species2 species3 species4 species5
#> v10          .        1        .        1        .
#> v100         1        1        .        1        .
#> v1000        1        .        1        1        .
#> v1001        1        .        .        1        .
#> v1002        1        .        .        1        .
#> v1003        1        .        .        1        .
# }

library(terra)
s <- vect(system.file("ex/nigeria.json", package="phyloregion"))
set.seed(1)
m <- as.data.frame(spatSample(s, 1000, method = "random"),
                   geom = "XY")[-1]
names(m) <- c("lon", "lat")
species <- paste0("sp", sample(1:100))
m$taxon <- sample(species, size = nrow(m), replace = TRUE)

pt <- points2comm(dat = m, res = 0.5) # This generates a list of two objects
head(pt[[1]])
#> 6 x 100 sparse Matrix of class "dgCMatrix"
#>   [[ suppressing 100 column names ‘sp1’, ‘sp10’, ‘sp100’ ... ]]
#>                                                                               
#> v100 . . . . . . . 1 . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . .
#> v101 . 1 . . . . . . . . . . . . . . . 1 . . . . . . . . . . . 1 . . . . . . .
#> v102 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v103 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v105 . . . . . . . . 1 . 1 . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v106 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#>                                                                               
#> v100 . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . .
#> v102 . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v103 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v105 1 . . . . . . . 1 . 1 . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v106 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#>                                                         
#> v100 . 1 . . . . . . . . . . . . . . . . . . . . . . . .
#> v101 . . 1 . . . . . . . . . . . . . . . . . . . . . . .
#> v102 . . . . . . . . . . . . . . . . . . . . . . . . . .
#> v103 . . . . . . . . 1 . . 1 . . . . . . . . . . . . . 1
#> v105 . . . . . 1 . . . . . . . . . 1 . . . . . . . . . .
#> v106 . . . . . . . . . . . . . . . . . . . 1 . . . . . .