annotate div_index.r @ 1:b67730406f1b draft

planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
author ecology
date Wed, 04 Jan 2023 13:21:30 +0000
parents
children bcbad4f83dec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
1 # author: "Jonathan Richir"
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
2 # date: "01 October 2022"
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
3
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
4
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
5 #Rscript
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
6
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
7 ###############################
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
8 ## ##
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
9 ###############################
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
10
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
11 #####Packages : dplyr
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
12 # tidyr
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
13 # readr
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
14 # writexl
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
15 # stringr
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
16 # readxl
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
17 # tibble
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
18 # lubridate
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
19 # cowplot
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
20 # magrittr
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
21 # rmarkdown
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
22 library(magrittr)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
23 library(dplyr)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
24 #####Load arguments
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
25
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
26 args <- commandArgs(trailingOnly = TRUE)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
27
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
28 #####Import data
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
29
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
30 if (length(args) < 1) {
b67730406f1b 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")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
32 }else {
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
33 qecnato0 <- args[1]
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
34
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
35 }
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
36
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
37 qecnato0 <- readRDS(qecnato0)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
38
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
39
b67730406f1b 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)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
41
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
42 bret_egmp_basq_qecb <- c(
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
43 "X..algues.brunes",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
44 "X..algues.rouges",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
45 "X..algues.vertes",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
46 "X..Cladophora",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
47 "X..Lithophyllum",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
48 "Nb.Littorina.obtusata",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
49 "Nb.Gibbula.cineraria",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
50 "Nb.Gibbula.pennanti",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
51 "Nb.Gibbula.umbilicalis",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
52 "Nb.Phallusia.mamillata",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
53 "Nb.Tethya.aurantium",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
54 "Nb.Spirobranchus.lamarckii.total",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
55 "Nb.spirorbis.total",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
56 "X..Eponges",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
57 "X..Ascidies.Coloniales",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
58 "X..Ascidies.Solitaires",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
59 "X..Bryozoaires.Dresses",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
60 "X..Balanes.Vivantes"
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
61 #, "X..Recouvrement.Sediment"
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
62 #, "X..Roche.Nue"
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
63 #, "X..Surface.Accolement"
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
64 )
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
65
b67730406f1b 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")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
67
b67730406f1b 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.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
69 "Nb.Necora.puber..Etrille.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
70 "Nb.Carcinus.maenas..Crabe.vert.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
71 "Nb.Nucella.lapilus..Pourpre.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
72 "Nb.Galathea..Galathées.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
73 "Nb.Lophozozymus.incisus..ancien.Xantho.incisus.",
b67730406f1b 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.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
75 "Nb.Haliotis.tuberculata..Ormeau.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
76 "Nb.Littorina.littorea..Bigorneau.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
77 "Nb.Xantho.pilipes..Xanthe.poilu.",
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
78 "Nb.Mimachlamys.varia..Pétoncle.noir.")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
79
b67730406f1b 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.")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
81
b67730406f1b 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
b67730406f1b 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")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
84
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
85 ## Diversity index
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
86
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
87
b67730406f1b 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).
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
89
b67730406f1b 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.
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
91
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
92 # function in a loop
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
93
b67730406f1b 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))
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
95
b67730406f1b 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
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
97 #bret_egmp_basq_qecb
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
98 #egmp_basq_qecb
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
99 #Bret_EGMP.BASQ_fishing
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
100 #EGMP.BASQ_fishing
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
101
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
102 # remove boulder variables
b67730406f1b 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")]
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
104
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
105 qecnato0$period <- as.character(qecnato0$period)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
106 qecnato0$Face <- as.character(qecnato0$Face)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
107
b67730406f1b 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)))
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
109
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
110 for (i in c(1:nrow(qecnato0))) {
b67730406f1b 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])
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
112
b67730406f1b 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.
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
114
b67730406f1b 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
b67730406f1b 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)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
117
b67730406f1b 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.])
b67730406f1b 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)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
120
b67730406f1b 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.
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
122
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
123
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
124 par(mfrow = c (1, 1))
b67730406f1b 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))
b67730406f1b 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))
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
127
b67730406f1b 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`
b67730406f1b 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)")
b67730406f1b 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`
b67730406f1b 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])
b67730406f1b 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`
b67730406f1b 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])
b67730406f1b 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`
b67730406f1b 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])
b67730406f1b 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`
b67730406f1b 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)")
b67730406f1b 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`
b67730406f1b 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])
b67730406f1b 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`
b67730406f1b 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])
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
142
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
143 # plot
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
144 par(mfrow = c(3, 2))
b67730406f1b 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))]),
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
146 function(cname) {
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
147 png(paste0(cname, "_histo.png"))
b67730406f1b 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]])))
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
149 dev.off()
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
150 }
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
151
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
152 )
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
153 par(mfrow = c(1,1))
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
154
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
155 div_list[[i]] <- adiv_i_df
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
156
b67730406f1b 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)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
158
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
159 }
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
160
b67730406f1b 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.
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
162
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
163
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
164 div_df <- do.call("rbind", div_list)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
165
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
166
b67730406f1b 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 "_" ...
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
168
b67730406f1b 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")
b67730406f1b 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 = "_")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
171
b67730406f1b 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
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
173
b67730406f1b 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.")
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
175
b67730406f1b 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)
b67730406f1b 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.)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
178
b67730406f1b 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)
b67730406f1b 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.))
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
181
b67730406f1b 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)
b67730406f1b 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)
b67730406f1b 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)
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
185
b67730406f1b planemo upload for repository https://github.com/Marie59/champ_blocs commit 0d86db7d42b608c386a54500064f5f9c9d7019a4
ecology
parents:
diff changeset
186 saveRDS(div_df, "div_df.RDS")
b67730406f1b 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")