This function counts the number of occurrences of specified species within a defined area.
The area can be specified using a shapefile or a two-letter country code. The function
uses the rgbif package to query species occurrences and returns a data.frame with the
results.
Arguments
- species
A data.frame containing the columns
family,genus, andspecies. These should be the taxonomic details of the species for which you want to count occurrences.- shapefile
A shapefile (with lat/long coordinates) defining the area of interest. The function will create a minimum bounding rectangle around the shapefile to query the species occurrences. Default is
NULL.- country
A two-letter country code (e.g., "DK" for Denmark) to define the area of interest. Default is
NULL.
Value
A data.frame with columns family, genus, species, and N where N
represents the number of occurrences of each species within the defined area.
Examples
# Example species data.frame
species <- structure(list(family = "Polytrichaceae", genus = "Atrichum",
species = "Atrichum undulatum"), row.names = c(NA, -1L),
class = c("tbl_df", "tbl", "data.frame"))
# Example 1: Using a country code
df_country <- count_presences(species, country = "DK")
print(df_country)
#> family genus species N
#> <char> <char> <char> <num>
#> 1: Polytrichaceae Atrichum Atrichum undulatum 1596
# Example 2: Using a shapefile
# Assuming "Aarhus.shp" is in the working directory
f <- system.file("ex/Aarhus.shp", package="SpeciesPoolR")
df_shapefile <- count_presences(species, shapefile = f)
print(df_shapefile)
#> family genus species N
#> <char> <char> <char> <num>
#> 1: Polytrichaceae Atrichum Atrichum undulatum 76
