Species Richness of Cetaceans along Coastal California

Raster of species richness of cetacean species off the coast of California utlizing a probability threshold.

code
analysis
raster
Author

Elmera Azadpour

Published

March 7, 2021

To access data, html and Rmd/qmd files:

  • the cetacean data can be found in the data folder of this repo; the Rmd and html files, denoted as a3-task2, can be found in the src folder
  • the qmd format can be found here

Load Packages

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6     ✔ purrr   0.3.4
✔ tibble  3.1.8     ✔ dplyr   1.0.9
✔ tidyr   1.2.0     ✔ stringr 1.4.0
✔ readr   2.1.2     ✔ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(here)
here() starts at /Users/elmeraa/Desktop/elmera/elmera
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(sf)
Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(raster)
Loading required package: sp

Attaching package: 'raster'

The following object is masked from 'package:dplyr':

    select
library(fasterize)

Attaching package: 'fasterize'

The following object is masked from 'package:graphics':

    plot

The following object is masked from 'package:base':

    plot
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
rgeos version: 0.5-9, (SVN revision 684)
 GEOS runtime version: 3.10.2-CAPI-1.16.0 
 Please note that rgeos will be retired by the end of 2023,
plan transition to sf functions using GEOS at your earliest convenience.
 GEOS using OverlayNG
 Linking to sp version: 1.4-7 
 Polygon checking: TRUE 

Read in data and stack files

cetacean <-  list.files(here("posts", "2021-03-07-cetacean-richness","ca_cetaceans"), full.names = TRUE)
cetacean_raster <- stack(cetacean)
cetacean_raster
class      : RasterStack 
dimensions : 12, 20, 240, 35  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent     : -125, -115, 32, 38  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
names      : Balaenoptera_acutorostrata, Balaenoptera_borealis, Balaenoptera_brydei, Balaenoptera_edeni, Balaenoptera_musculus, Balaenoptera_physalus, Berardius_bairdii, Delphinus_capensis, Delphinus_delphis, Eschrichtius_robustus, Eubalaena_japonica, Globicephala_macrorhynchus, Grampus_griseus, Indopacetus_pacificus, Kogia_breviceps, ... 
min values :                       0.11,                  0.02,                0.03,               0.03,                  0.01,                  0.06,              0.01,               0.03,              0.03,                  0.11,               0.59,                       0.02,            0.03,                  0.01,            0.03, ... 
max values :                       1.00,                  1.00,                1.00,               1.00,                  1.00,                  1.00,              1.00,               0.63,              1.00,                  1.00,               1.00,                       1.00,            1.00,                  0.47,            1.00, ... 
plot(cetacean_raster)

Apply probability threshold (of 0.6 or greater) to determine presence or non-presence

aquamap_fun <- function(x, thresh = 0.6){
  y <- ifelse(x >= thresh, 1, 0)
  return(y)
}

aquamap <- calc(cetacean_raster, fun = aquamap_fun)
species_richness1 <- calc(aquamap, fun = sum, na.rm = TRUE)
plot(species_richness1)

Converting to dataframe and plotting

aquamap_df <- raster::rasterToPoints(species_richness1) %>% 
  as.data.frame()

states110 <- ne_download(scale = 110, type = 'states', category = 'cultural', returnclass = "sf") %>% filter(name %in% c("California"))
Warning in check_data_exist(scale = scale, category = category, type = type):
your combination of type, category, scale seem not to exist in the list of
Natural Earth data so you may get a download fail message. Check ?ne_download or
http://www.naturalearthdata.com/features/ to see data availability.

Warning in check_data_exist(scale = scale, category = category, type = type):
your combination of type, category, scale seem not to exist in the list of
Natural Earth data so you may get a download fail message. Check ?ne_download or
http://www.naturalearthdata.com/features/ to see data availability.
OGR data source with driver: ESRI Shapefile 
Source: "/private/var/folders/r0/gbtncpg92w3chydzw5fw5bnr0000gn/T/Rtmp0dFxl2", layer: "ne_110m_admin_1_states_provinces_lakes"
with 51 features
It has 121 fields
Integer64 fields read as strings:  ne_id 
ggplot() +
geom_raster(data = aquamap_df, aes(x=x,y=y, fill = layer)) +
  geom_sf(data = states110) +
  scale_fill_gradient2(low = "red", mid = "white", high = "blue") +
  labs(x = "Longitude", y = "Latitude", title = "Species Richness of Cetaceans along Coastal California", fill = "Number of Cetacean Species") +
  theme_classic()

Fig. 1 Species Richness of 16 Cetacean Species along the Coast of California. Presence of Cetacean species was determined with with a probability threshold of 0.6 or greater.

Citation:

  • Kaschner, K., Rius-Barile, J., Kesner-Reyes, K., Garilao, C., Kullander, S., Rees, T., & Froese, R. (2016). AquaMaps: Predicted range maps for aquatic species. www.aquamaps.org