knitr::opts_chunk$set(
  message = FALSE,
  collapse = TRUE,
  comment = "#>",
  fig.width = 9,
  fig.height = 3.8,
  warning = FALSE
)

```{R load_packages} library(HomogenFishOntario) library(rfishbase)

# Context

This is a small web page that guides the reader through the code we used to carry out the analysis in [Cazelles (2019) DOI: 10.1111/gcb.14829](https://onlinelibrary.wiley.com/doi/abs/10.1111/gcb.14829). Note that `pipeline()` is a function that runs the entire analysis. We are not allowed to share the exact lake locations, therefore the context map and 3 supplementary figures cannot be reproduced.


# Data

The file `sf_bsm_ahi` includes presence and absence in both survey for all
species as well as the lake descriptors and climate data.


```{R map, fig.height = 7}
head(sf_bsm_ahi[, 1:10])

Species characteristics

Taxonomic hierarchy

We used an0_retrieve_species_info() to retrieved taxonomic hierarchy. It basically wraps around taxize functions. As an example, to retrieve taxonomic hierarchy for white sucker (Catostomus commersonii) and lake trout (Salvelinus namaycush), we ran:

```{R taxo} sps <- c("Catostomus commersonii", "Salvelinus namaycush") taxo <- an0_retrieve_species_info(sps) taxo

### Other traits

We retrieved data from the literature and from
[Fishbase](http://www.fishbase.org/search.php) using the `species()` function of
[rfishbase](https://cran.r-project.org/web/packages/rfishbase/vignettes/tutorial.html)
(after validating species names with `validate_names()`). For the two species
we used above as an example, we would run:

```{R}
fie <-  c("LongevityWild", "UsedforAquaculture", "UsedasBait", "GameFish",
   "Importance")
species(sps, field = fie)

df_species_info

We actually ran the code described above for the entire set of species and stored the data thereby obtained in df_species_info.

names(df_species_info)
head(df_species_info[, 1:5])

Gains and losses

Gains and losses are computed with an1_gain_loss():

```{R gainloss} galo <- an1_gain_loss(sf_bsm_ahi) names(galo) head(galo$sf_bsm_ahi[, 1:3])

### Occurrence

Occurrence data for every species are obtained by running  `an2_occurrence_species()`:

```{R occurrence}
spoc <- an2_occurrence_species(galo)
names(spoc)
head(spoc[, 1:6])

Regressions

Regression are performed via an3_regressions(); below we show the summary for the best model obtained for the regression $\Delta$FTD as response variables and climate data as explanatory variables:

```{R reg} mods <- an3_regressions(galo, spoc) summary(mods[[2]][[2]])

### Contributions to beta

Contributions of individual species to beta diversity metrics are computed with `an4_contributions_beta()`:

```{R contr}
cobe <- an4_contributions_beta(galo, spoc)
names(cobe)
head(cobe$contrib[, 1:8])

Figures

Every figure of the study (except the context map) are including in this package as a function (fig[1-6]_*() for figures in the main text and figS[1-8]_*() for figures in the Supplementary Information). For a given figure, the corresponding function draws the figure and exported as a png files with a resolution of 900 dpi in the folder output (created if it does not exist).

For instance to obtain figure 2, one need to run:

fig2_homogenization(galo)

{R, echo = FALSE} fig2_homogenization(galo, asfinal = FALSE)

which writes the figure above in output/fig2_homogenization.png. Similarly, fig3_regressions(galo, mods) creates output/fig2_homogenization.png (and so forth).

Note that as we are not allowed to share lake location Figure S3 S4 and S6 are not reproducible.



McCannLab/HomogenFishOntario documentation built on Nov. 20, 2021, 1:25 a.m.