Mercurial > repos > ecology > cb_ivr
annotate div_index.r @ 1:83a4d3b47184 draft default tip
planemo upload for repository https://github.com/Marie59/champ_blocs commit 075fd90d1a39ae7912b48549e5537971635b9620
| author | ecology |
|---|---|
| date | Sat, 18 Mar 2023 16:48:40 +0000 |
| parents | 89f977a3a256 |
| children |
| rev | line source |
|---|---|
|
0
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
1 # author: "Jonathan Richir" |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
2 # date: "01 October 2022" |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
3 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
4 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
5 #Rscript |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
6 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
7 ############################### |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
8 ## ## |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
9 ############################### |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
10 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
11 #####Packages : dplyr |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
12 # tidyr |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
13 #####Load arguments |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
14 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
15 args <- commandArgs(trailingOnly = TRUE) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
16 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
17 #####Import data |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
18 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
19 if (length(args) < 1) { |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
20 stop("This tool needs at least 1 argument") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
21 }else { |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
22 qecnato0 <- args[1] |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
23 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
24 } |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
25 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
26 qecnato0 <- readRDS(qecnato0) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
27 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
28 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
29 # first, create vector (4) for qecb and fishing by region (same as above) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
30 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
31 bret_egmp_basq_qecb <- c( |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
32 "X..algues.brunes", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
33 "X..algues.rouges", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
34 "X..algues.vertes", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
35 "X..Cladophora", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
36 "X..Lithophyllum", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
37 "Nb.Littorina.obtusata", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
38 "Nb.Gibbula.cineraria", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
39 "Nb.Gibbula.pennanti", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
40 "Nb.Gibbula.umbilicalis", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
41 "Nb.Phallusia.mamillata", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
42 "Nb.Tethya.aurantium", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
43 "Nb.Spirobranchus.lamarckii.total", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
44 "Nb.spirorbis.total", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
45 "X..Eponges", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
46 "X..Ascidies.Coloniales", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
47 "X..Ascidies.Solitaires", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
48 "X..Bryozoaires.Dresses", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
49 "X..Balanes.Vivantes" |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
50 #, "X..Recouvrement.Sediment" |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
51 #, "X..Roche.Nue" |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
52 #, "X..Surface.Accolement" |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
53 ) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
54 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
55 egmp_basq_qecb <- c("Nb.Crassostrea.gigas", "Nb.Ostrea.edulis", "X..Mytilus.sp.", "X..Hermelles", "X..Hydraires") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
56 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
57 bret_egmp_basq_fishing <- c("Nb.Cancer.pagurus..Tourteau.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
58 "Nb.Necora.puber..Etrille.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
59 "Nb.Carcinus.maenas..Crabe.vert.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
60 "Nb.Nucella.lapilus..Pourpre.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
61 "Nb.Galathea..Galathées.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
62 "Nb.Lophozozymus.incisus..ancien.Xantho.incisus.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
63 "Nb.Palaemon.sp..Crevette.bouquet.ou.crevette.rose.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
64 "Nb.Haliotis.tuberculata..Ormeau.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
65 "Nb.Littorina.littorea..Bigorneau.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
66 "Nb.Xantho.pilipes..Xanthe.poilu.", |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
67 "Nb.Mimachlamys.varia..Pétoncle.noir.") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
68 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
69 egmp_basq_fishing <- c("Nb.Eriphia.verrucosa..Crabe.verruqueux.", "Nb.Octopus.vulgaris..Poulpe.", "Nb.Paracentrotus.lividus..Oursin.", "Nb.Stramonita.haemastoma..Pourpre.bouche.de.sang.") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
70 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
71 # here I can choose to either replace spirorbis and/or spirobranchus by their log10 transformation in bret_egmp_basq_qecb vector |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
72 bret_egmp_basq_qecb <- replace(bret_egmp_basq_qecb, bret_egmp_basq_qecb == "Nb.spirorbis.total", "log10.Nb.spirorbis.total") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
73 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
74 ## Diversity index |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
75 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
76 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
77 # 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). |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
78 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
79 # 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. |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
80 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
81 # function in a loop |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
82 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
83 row.names(qecnato0) <- c(paste0(qecnato0$region.site_year_month_day, "_", qecnato0$Quadrat.bis, "_", qecnato0$Type.Bloc, "_", qecnato0$Numéro.Bloc.échantillon, "_", qecnato0$Face)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
84 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
85 # later on I can copy-paste above code to recreate variable names vector |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
86 #bret_egmp_basq_qecb |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
87 #egmp_basq_qecb |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
88 #Bret_EGMP.BASQ_fishing |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
89 #EGMP.BASQ_fishing |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
90 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
91 # remove boulder variables |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
92 bret_egmp_basq_qecb <- bret_egmp_basq_qecb[! bret_egmp_basq_qecb %in% c("X..Recouvrement.Sediment", "X..Roche.Nue", "X..Surface.Accolement")] |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
93 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
94 qecnato0$period <- as.character(qecnato0$period) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
95 qecnato0$Face <- as.character(qecnato0$Face) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
96 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
97 div_list <- vector("list", length(unique(qecnato0$site_year_month_day))) |
|
1
83a4d3b47184
planemo upload for repository https://github.com/Marie59/champ_blocs commit 075fd90d1a39ae7912b48549e5537971635b9620
ecology
parents:
0
diff
changeset
|
98 library(dplyr) |
|
0
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
99 for (i in c(1:nrow(qecnato0))) { |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
100 div_i <- dplyr::filter(qecnato0, site_year_month_day == qecnato0$site_year_month_day[i]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
101 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
102 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. |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
103 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
104 #8 remove empty row cfr: In speciesdiv(div_i[, var.]) & divparam(div_i[, var.]) : empty communities should be discarded |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
105 div_i <- dplyr::filter(div_i, rowSums(div_i[, var.]) > 0) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
106 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
107 div_i_speciesdiv <- adiv::speciesdiv(div_i[, var.]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
108 adiv_i_df <- data.frame(div_i_speciesdiv) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
109 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
110 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. |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
111 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
112 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
113 par(mfrow = c (1, 1)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
114 plot(adiv::divparam(div_i[, var.], q = 0), main = unique(div_i$site_year_month_day)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
115 plot(adiv::divparam(div_i[, var.], q = 0:10), legend = FALSE, main = unique(div_i$site_year_month_day)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
116 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
117 adiv_i_df$x <- div_i_divparam$div$`1` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
118 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[1], " (equi. richness)") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
119 adiv_i_df$x <- div_i_divparam$div$`2` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
120 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[2]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
121 adiv_i_df$x <- div_i_divparam$div$`3` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
122 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[3]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
123 adiv_i_df$x <- div_i_divparam$div$`4` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
124 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[4]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
125 adiv_i_df$x <- div_i_divparam$div$`5` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
126 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[5], " (equi. Simpson)") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
127 adiv_i_df$x <- div_i_divparam$div$`6` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
128 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[6]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
129 adiv_i_df$x <- div_i_divparam$div$`7` |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
130 colnames(adiv_i_df)[which(colnames(adiv_i_df) == "x")] <- paste0("Para. ISD, q = ", div_i_divparam$q[7]) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
131 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
132 # plot |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
133 par(mfrow = c(3, 2)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
134 sapply(names(adiv_i_df[, c(1, 8, 2, 3, 12, 4:7, 9:11, 13:ncol(adiv_i_df))]), |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
135 function(cname) { |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
136 png(paste0(cname, "_histo.png")) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
137 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]]))) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
138 dev.off() |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
139 } |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
140 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
141 ) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
142 par(mfrow = c(1,1)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
143 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
144 div_list[[i]] <- adiv_i_df |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
145 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
146 rm(div_i, adiv_i_df, div_i_speciesdiv, div_i_divparam) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
147 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
148 } |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
149 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
150 # 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. |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
151 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
152 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
153 div_df <- do.call("rbind", div_list) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
154 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
155 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
156 # There is an issue with region.terri that are merged with no "_" ... |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
157 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
158 div_df <- tibble::add_column(div_df, rownames. = rownames(div_df), .before = "richness") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
159 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 = "_") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
160 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
161 # I therefore add these lines to solve that issue |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
162 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
163 div_df <- tibble::add_column(div_df, terri. = substring(div_df$region.terri., nchar(div_df$region.terri.)-3), .after = "region.terri.") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
164 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
165 div_df$region.terri. <- substring(div_df$region.terri., 1, nchar(div_df$region.terri)-4) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
166 div_df <- dplyr::rename(div_df, region = region.terri.) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
167 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
168 div_df$site_year_month_day <- paste0(div_df$terri., "_", div_df$site_year_month_day) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
169 div_df <- subset(div_df, select = -c(terri.)) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
170 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
171 div_df$Type.Bloc <- as.factor(div_df$Type.Bloc) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
172 div_df$Face <- as.factor(div_df$Face) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
173 div_df$Numéro.Bloc.échantillon <- as.integer(div_df$Numéro.Bloc.échantillon) |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
174 |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
175 saveRDS(div_df, "div_df.RDS") |
|
89f977a3a256
planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff
changeset
|
176 write.table(div_df, "Valeurs_stat.tabular", row.names = FALSE, quote = FALSE, sep = "\t", dec = ".", fileEncoding = "UTF-8") |
