Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
8Ginette8 authored Jan 31, 2025
1 parent bb16133 commit f896744
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ You can install the development version from GitHub with:
``` r
remotes::install_github("8Ginette8/gbif.range")
library(gbif.range)
library(terra)
library(rnaturalearth)
```

## Example
Expand All @@ -66,12 +64,12 @@ Let's download worldwide the records of *Panthera tigris* only based on true obs

``` r
# Download
obs_pt = get_gbif(sp_name = "Panthera tigris")
obs_pt <- get_gbif(sp_name = "Panthera tigris")

# Plot species records
countries = ne_countries(type = "countries",returnclass = "sv")
plot(countries,col = "#bcbddc")
points(obs_pt[,c("decimalLongitude","decimalLatitude")],pch=20,col="#99340470",cex=1.5)
countries <- rnaturalearth::ne_countries(type = "countries", returnclass = "sv")
terra::plot(countries, col = "#bcbddc")
points(obs_pt[, c("decimalLongitude","decimalLatitude")], pch = 20, col = "#99340470", cex = 1.5)
```

![image](https://github.com/user-attachments/assets/2af40d4a-f1e5-47ba-a9ad-9e6da32a9df4)
Expand All @@ -80,17 +78,17 @@ points(obs_pt[,c("decimalLongitude","decimalLatitude")],pch=20,col="#99340470",c
Note that the function did not manage to get rid of observations found in the US and germany (observations from zoos most likely). We can also retrieve the tiger **IUCN red list status**, and its scientific names (accepted and synonyms) that were used in the download with the **GBIF backbone taxonomy**. If all = TRUE, additonal children and related doubtful names may also be extracted (not used in *get_gbif()*):

``` r
get_status("Panthera tigris",all=FALSE)
get_status("Panthera tigris", all = FALSE)
```

Let's now extract the terrestrial ecoregions of the world (Nature Conservancy) and generate the distributional range map of *Panthera tigris* :

``` r
# Download ecoregion and read
eco_terra = read_bioreg(bioreg_name = "eco_terra", save_dir = NULL)
eco_terra <- read_bioreg(bioreg_name = "eco_terra", save_dir = NULL)

# Range
range_tiger = get_range(occ_coord = obs_pt,
range_tiger <- get_range(occ_coord = obs_pt,
bioreg = eco_terra,
bioreg_name = "ECO_NAME",
degrees_outlier = 6,
Expand All @@ -100,8 +98,8 @@ range_tiger = get_range(occ_coord = obs_pt,
Let's plot the result now:

``` r
plot(countries,col = "#bcbddc")
plot(range_tiger$range_output,col = "#238b45",add = TRUE,axes = FALSE,legend = FALSE)
terra::plot(countries, col = "#bcbddc")
terra::plot(range_tiger$range_output, col = "#238b45", add = TRUE, axes = FALSE, legend = FALSE)
```

![image](https://github.com/user-attachments/assets/6cf6c8c3-7e0f-4754-9806-05821091173c)
Expand All @@ -127,16 +125,16 @@ Additonally, if the in-house ecoregions are too coarse for a given geographic re

``` r
# Let's download the observations of Arctostaphylos alpinus in the European Alps:
shp_lonlat = vect(paste0(system.file(package = "gbif.range"),"/extdata/shp_lonlat.shp"))
obs_arcto = get_gbif("Arctostaphylos alpinus",geo=shp_lonlat)
shp_lonlat <- terra::vect(paste0(system.file(package = "gbif.range"), "/extdata/shp_lonlat.shp"))
obs_arcto <- get_gbif("Arctostaphylos alpinus", geo = shp_lonlat)

# Create an ecoregion layer of 200 classes, based on two environmental spatial layers:
rst = rast(paste0(system.file(package = "gbif.range"),"/extdata/rst.tif"))
my_eco = make_ecoregion(rst,200)
rst <- terra::rast(paste0(system.file(package = "gbif.range"), "/extdata/rst.tif"))
my_eco <- make_ecoregion(rst, 200)

# Create the range map based on our custom ecoregion
# (always set 'EcoRegion' as a name when using a make_ecoregion() output):
range_arcto = get_range(occ_coord = obs_arcto,
range_arcto <- get_range(occ_coord = obs_arcto,
bioreg = my_eco,
bioreg_name = "EcoRegion",
res = 20,
Expand All @@ -151,9 +149,9 @@ Here we adapted the extra-parameters to the extent of the study area, e.g., (i)

``` r
# Plot
plot(crop(countries,ext(rst)),col = "#bcbddc")
plot(range_arcto$range_output,add = TRUE,col = "darkgreen",axes = FALSE,legend = FALSE)
points(obs_arcto[,c("decimalLongitude","decimalLatitude")],pch = 20,col = "#99340470",cex=1)
terra::plot(crop(countries,ext(rst)), col = "#bcbddc")
terra::plot(range_arcto$range_output, add = TRUE, col = "darkgreen", axes = FALSE, legend = FALSE)
points(obs_arcto[, c("decimalLongitude","decimalLatitude")], pch = 20, col = "#99340470", cex = 1)
```

![image](https://github.com/user-attachments/assets/832e6d57-f7cb-402a-985e-fdf05d4f96aa)
Expand All @@ -165,28 +163,28 @@ Let's reapply the same process as for Panthera tigris, but with the marine speci
⚠️Notes that the download takes here longer unless the parameter *occ_samp* is used. Altough giving **less precise observational distribution**, *occ_samp* allows to extract a **subsample of *n* GBIF observations** per created tiles over the study area:

``` r
obs_dd = get_gbif("Delphinus delphis",occ_samp = 1000) # Here the example is a sample of 1000 observations per geographic tile
get_status("Delphinus delphis",all = TRUE) # Here the list is longer because 'all=TRUE' includes every names (even doubtful)
obs_dd <- get_gbif("Delphinus delphis", occ_samp = 1000) # Here the example is a sample of 1000 observations per geographic tile
get_status("Delphinus delphis", all = TRUE) # Here the list is longer because 'all=TRUE' includes every names (even doubtful)
```

Let's now generate three range maps of *Delphinus delphis* using the *eco.marine* as ecoregion shapefile:

``` r
# Download ecoregion and read
eco_marine = read_bioreg(bioreg_name = "eco_marine", save_dir = NULL)
eco_marine <- read_bioreg(bioreg_name = "eco_marine", save_dir = NULL)

# Range from different levels
range_dd1 = get_range(obs_dd,eco_marine,"ECOREGION")
range_dd2 = get_range(obs_dd,eco_marine,"PROVINCE")
range_dd3 = get_range(obs_dd,eco_marine,"REALM")
range_dd1 <- get_range(obs_dd, eco_marine, "ECOREGION")
range_dd2 <- get_range(obs_dd, eco_marine, "PROVINCE")
range_dd3 <- get_range(obs_dd, eco_marine, "REALM")
```

The three results are pretty similar because most of the observations are near the coast. But let's plot the first more fine result:

``` r
plot(countries,col="#bcbddc")
plot(range_dd3$range_output,col = "#238b45",add = TRUE,axes = FALSE,legend = FALSE)
points(obs_dd[,c("decimalLongitude","decimalLatitude")],pch = 20,col = "#99340470",cex = 1)
terra::plot(countries, col = "#bcbddc")
terra::plot(range_dd3$range_output, col = "#238b45", add = TRUE, axes = FALSE, legend = FALSE)
points(obs_dd[, c("decimalLongitude","decimalLatitude")], pch = 20, col = "#99340470", cex = 1)
```

<img width=80% height=80% src="https://github.com/8Ginette8/gbif.range/assets/43674773/a84c5dcf-f2c7-4722-b2ed-d13502d45eb1">
Expand Down

0 comments on commit f896744

Please sign in to comment.