Mercurial > repos > ecology > cb_dissim
annotate div_index.r @ 1:ffaa9a71b2d2 draft
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
author | ecology |
---|---|
date | Wed, 04 Jan 2023 13:21:53 +0000 |
parents | |
children | 8dc082da41c1 |
rev | line source |
---|---|
1
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
1 # author: "Jonathan Richir" |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
2 # date: "01 October 2022" |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
3 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
4 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
5 #Rscript |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
6 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
7 ############################### |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
8 ## ## |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
9 ############################### |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
10 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
11 #####Packages : dplyr |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
12 # tidyr |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
13 # readr |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
14 # writexl |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
15 # stringr |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
16 # readxl |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
17 # tibble |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
18 # lubridate |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
19 # cowplot |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
20 # magrittr |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
21 # rmarkdown |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
22 library(magrittr) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
23 library(dplyr) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
24 #####Load arguments |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
25 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
26 args <- commandArgs(trailingOnly = TRUE) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
27 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
28 #####Import data |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
29 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
30 if (length(args) < 1) { |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
31 stop("This tool needs at least 1 argument") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
32 }else { |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
33 qecnato0 <- args[1] |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
34 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
35 } |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
36 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
37 qecnato0 <- readRDS(qecnato0) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
38 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
39 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
40 # first, create vector (4) for qecb and fishing by region (same as above) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
41 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
42 bret_egmp_basq_qecb <- c( |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
43 "X..algues.brunes", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
44 "X..algues.rouges", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
45 "X..algues.vertes", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
46 "X..Cladophora", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
47 "X..Lithophyllum", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
48 "Nb.Littorina.obtusata", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
49 "Nb.Gibbula.cineraria", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
50 "Nb.Gibbula.pennanti", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
51 "Nb.Gibbula.umbilicalis", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
52 "Nb.Phallusia.mamillata", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
53 "Nb.Tethya.aurantium", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
54 "Nb.Spirobranchus.lamarckii.total", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
55 "Nb.spirorbis.total", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
56 "X..Eponges", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
57 "X..Ascidies.Coloniales", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
58 "X..Ascidies.Solitaires", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
59 "X..Bryozoaires.Dresses", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
60 "X..Balanes.Vivantes" |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
61 #, "X..Recouvrement.Sediment" |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
62 #, "X..Roche.Nue" |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
63 #, "X..Surface.Accolement" |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
64 ) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
65 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
66 egmp_basq_qecb <- c("Nb.Crassostrea.gigas", "Nb.Ostrea.edulis", "X..Mytilus.sp.", "X..Hermelles", "X..Hydraires") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
67 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
68 bret_egmp_basq_fishing <- c("Nb.Cancer.pagurus..Tourteau.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
69 "Nb.Necora.puber..Etrille.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
70 "Nb.Carcinus.maenas..Crabe.vert.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
71 "Nb.Nucella.lapilus..Pourpre.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
72 "Nb.Galathea..Galathées.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
73 "Nb.Lophozozymus.incisus..ancien.Xantho.incisus.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
74 "Nb.Palaemon.sp..Crevette.bouquet.ou.crevette.rose.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
75 "Nb.Haliotis.tuberculata..Ormeau.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
76 "Nb.Littorina.littorea..Bigorneau.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
77 "Nb.Xantho.pilipes..Xanthe.poilu.", |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
78 "Nb.Mimachlamys.varia..Pétoncle.noir.") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
79 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
80 egmp_basq_fishing <- c("Nb.Eriphia.verrucosa..Crabe.verruqueux.", "Nb.Octopus.vulgaris..Poulpe.", "Nb.Paracentrotus.lividus..Oursin.", "Nb.Stramonita.haemastoma..Pourpre.bouche.de.sang.") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
81 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
82 # here I can choose to either replace spirorbis and/or spirobranchus by their log10 transformation in bret_egmp_basq_qecb vector |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
83 bret_egmp_basq_qecb <- replace(bret_egmp_basq_qecb, bret_egmp_basq_qecb == "Nb.spirorbis.total", "log10.Nb.spirorbis.total") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
84 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
85 ## Diversity index |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
86 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
87 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
88 # adiv contains two main functions for species diversity indices: speciesdiv, which includes widely used indices such as species richness and the Shannon index, and divparam, which includes indices that have a parameter to control the importance given to rare versus abundant species in diversity measurements (Pavoine (2020) - adiv: An r package to analyse biodiversity in ecology). |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
89 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
90 # NB: just like for dissimilarity distance matrices, no sense to use the "fishing" variable lists, because either they are present for the bloc mobile and not for the bloc fixe (therefore false higher diversity for bloc mobile), either they are repeated between face supérieure and face inférieure of bloc mobile. |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
91 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
92 # function in a loop |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
93 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
94 row.names(qecnato0) <- c(paste0(qecnato0$region.site_year_month_day, "_", qecnato0$Quadrat.bis, "_", qecnato0$Type.Bloc, "_", qecnato0$Numéro.Bloc.échantillon, "_", qecnato0$Face)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
95 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
96 # later on I can copy-paste above code to recreate variable names vector |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
97 #bret_egmp_basq_qecb |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
98 #egmp_basq_qecb |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
99 #Bret_EGMP.BASQ_fishing |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
100 #EGMP.BASQ_fishing |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
101 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
102 # remove boulder variables |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
103 bret_egmp_basq_qecb <- bret_egmp_basq_qecb[! bret_egmp_basq_qecb %in% c("X..Recouvrement.Sediment", "X..Roche.Nue", "X..Surface.Accolement")] |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
104 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
105 qecnato0$period <- as.character(qecnato0$period) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
106 qecnato0$Face <- as.character(qecnato0$Face) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
107 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
108 div_list <- vector("list", length(unique(qecnato0$site_year_month_day))) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
109 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
110 for (i in c(1:nrow(qecnato0))) { |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
111 div_i <- dplyr::filter(qecnato0, site_year_month_day == qecnato0$site_year_month_day[i]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
112 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
113 ifelse(unique(div_i$region) == "Bretagne", var. <- c(bret_egmp_basq_qecb), var. <- c(bret_egmp_basq_qecb, egmp_basq_qecb)) # Qu. : Why can't R's ifelse statements return vectors? => you can circumvent the problem if you assign the result inside the ifelse. |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
114 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
115 #8 remove empty row cfr: In speciesdiv(div_i[, var.]) & divparam(div_i[, var.]) : empty communities should be discarded |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
116 div_i <- dplyr::filter(div_i, rowSums(div_i[, var.]) > 0) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
117 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
118 div_i_speciesdiv <- adiv::speciesdiv(div_i[, var.]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
119 adiv_i_df <- data.frame(div_i_speciesdiv) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
120 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
121 div_i_divparam <- adiv::divparam(div_i[, var.], q = c(0, 0.25, 0.5, 1, 2, 4, 8)) # When q increases, abundant species are overweighted compared to rare species, we thus expect that the evenness in species weights decreases. |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
122 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
123 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
124 par(mfrow = c (1, 1)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
125 plot(adiv::divparam(div_i[, var.], q = 0), main = unique(div_i$site_year_month_day)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
126 plot(adiv::divparam(div_i[, var.], q = 0:10), legend = FALSE, main = unique(div_i$site_year_month_day)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
127 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
128 adiv_i_df$x <- div_i_divparam$div$`1` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
129 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[1], " (equi. richness)") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
130 adiv_i_df$x <- div_i_divparam$div$`2` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
131 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[2]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
132 adiv_i_df$x <- div_i_divparam$div$`3` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
133 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[3]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
134 adiv_i_df$x <- div_i_divparam$div$`4` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
135 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[4]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
136 adiv_i_df$x <- div_i_divparam$div$`5` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
137 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[5], " (equi. Simpson)") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
138 adiv_i_df$x <- div_i_divparam$div$`6` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
139 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[6]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
140 adiv_i_df$x <- div_i_divparam$div$`7` |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
141 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[7]) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
142 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
143 # plot |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
144 par(mfrow = c(3, 2)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
145 sapply(names(adiv_i_df[, c(1, 8, 2, 3, 12, 4:7, 9:11, 13:ncol(adiv_i_df))]), |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
146 function(cname) { |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
147 png(paste0(cname, "_histo.png")) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
148 hist(adiv_i_df[, c(1, 8, 2, 3, 12, 4:7, 9:11, 13:ncol(adiv_i_df))][[cname]], main = "", xlab = cname, breaks = length(unique(adiv_i_df[, c(1, 8, 2, 3, 12, 4:7, 9:11, 13:ncol(adiv_i_df))][[cname]]))) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
149 dev.off() |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
150 } |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
151 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
152 ) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
153 par(mfrow = c(1,1)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
154 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
155 div_list[[i]] <- adiv_i_df |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
156 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
157 rm(div_i, adiv_i_df, div_i_speciesdiv, div_i_divparam) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
158 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
159 } |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
160 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
161 # for the error message due to richness NA data => 35 observations in 21 surveys; no reason to remove these data "...remo", was checked in the complete script. |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
162 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
163 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
164 div_df <- do.call("rbind", div_list) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
165 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
166 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
167 # There is an issue with region.terri that are merged with no "_" ... |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
168 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
169 div_df <- tibble::add_column(div_df, rownames. = rownames(div_df), .before = "richness") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
170 div_df <- tidyr::separate(div_df, rownames., into = c("region.terri.", "site_year_month_day", "Quadrat.bis", "Type.Bloc", "Numéro.Bloc.échantillon", "Face"), sep = "_") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
171 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
172 # I therefore add these lines to solve that issue |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
173 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
174 div_df <- tibble::add_column(div_df, terri. = substring(div_df$region.terri., nchar(div_df$region.terri.)-3), .after = "region.terri.") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
175 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
176 div_df$region.terri. <- substring(div_df$region.terri., 1, nchar(div_df$region.terri)-4) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
177 div_df <- dplyr::rename(div_df, region = region.terri.) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
178 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
179 div_df$site_year_month_day <- paste0(div_df$terri., "_", div_df$site_year_month_day) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
180 div_df <- subset(div_df, select = -c(terri.)) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
181 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
182 div_df$Type.Bloc <- as.factor(div_df$Type.Bloc) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
183 div_df$Face <- as.factor(div_df$Face) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
184 div_df$Numéro.Bloc.échantillon <- as.integer(div_df$Numéro.Bloc.échantillon) |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
185 |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
186 saveRDS(div_df, "div_df.RDS") |
ffaa9a71b2d2
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
187 write.table(div_df, "Valeurs_stat.tabular", row.names = FALSE, quote = FALSE, sep = "\t", dec = ".", fileEncoding = "UTF-8") |