Mercurial > repos > ecology > ecology_stat_presence_abs
annotate graph_stat_presence_abs.r @ 1:9a2e0195bb43 draft default tip
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
author | ecology |
---|---|
date | Fri, 13 Aug 2021 18:18:21 +0000 |
parents | e5552099d0e3 |
children |
rev | line source |
---|---|
0
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
1 #Rscript |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
2 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
3 ################################ |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
4 ## Median and dispersion ## |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
5 ################################ |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
6 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
7 #####Packages : Cowplot |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
8 # ggplot2 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
9 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
10 #####Load arguments |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
11 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
12 args <- commandArgs(trailingOnly = TRUE) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
13 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
14 if (length(args) == 0) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
15 stop("This tool needs at least one argument") |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
16 }else{ |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
17 table <- args[1] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
18 hr <- args[2] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
19 var <- as.numeric(args[3]) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
20 spe <- as.numeric(args[4]) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
21 loc <- as.numeric(args[5]) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
22 time <- as.numeric(args[6]) |
1
9a2e0195bb43
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
0
diff
changeset
|
23 source(args[7]) |
0
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
24 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
25 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
26 if (hr == "false") { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
27 hr <- FALSE |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
28 }else{ |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
29 hr <- TRUE |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
30 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
31 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
32 #####Import data |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
33 data <- read.table(table, sep = "\t", dec = ".", header = hr, fill = TRUE, encoding = "UTF-8") |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
34 data <- na.omit(data) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
35 colvar <- colnames(data)[var] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
36 colspe <- colnames(data)[spe] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
37 colloc <- colnames(data)[loc] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
38 coltime <- colnames(data)[time] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
39 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
40 data <- data[grep("^$", data[, spe], invert = TRUE), ] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
41 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
42 #####Your analysis |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
43 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
44 ####Median and data dispersion#### |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
45 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
46 #Median |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
47 graph_median <- function(data, var) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
48 graph_median <- ggplot2::ggplot(data, ggplot2::aes_string(y = var)) + |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
49 ggplot2::geom_boxplot(color = "darkblue") + |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
50 ggplot2::theme(legend.position = "none") + ggplot2::ggtitle("Median") |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
51 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
52 return(graph_median) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
53 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
54 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
55 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
56 #Dispersion |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
57 dispersion <- function(data, var, var2) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
58 graph_dispersion <- ggplot2::ggplot(data) + |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
59 ggplot2::geom_point(ggplot2::aes_string(x = var2, y = var, color = var2)) + |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
60 ggplot2::scale_fill_brewer(palette = "Set3") + |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
61 ggplot2::theme(legend.position = "none", axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust = 1), plot.title = ggplot2::element_text(color = "black", size = 12, face = "bold")) + ggplot2::ggtitle("Dispersion") |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
62 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
63 return(graph_dispersion) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
64 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
65 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
66 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
67 #The 2 graph |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
68 med_disp <- function(med, disp) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
69 graph <- cowplot::plot_grid(med, disp, ncol = 1, nrow = 2, vjust = -5, scales = "free") |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
70 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
71 ggplot2::ggsave("Med_Disp.png", graph, width = 12, height = 20, units = "cm") |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
72 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
73 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
74 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
75 #### Zero problem in data #### |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
76 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
77 #Put data in form |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
78 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
79 data_num <- make_table_analyse(data, colvar, colspe, colloc, coltime) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
80 nb_spe <- length(unique(data[, spe])) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
81 nb_col <- ncol(data_num) - nb_spe + 1 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
82 data_num <- data_num[, nb_col:ncol(data_num)] |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
83 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
84 #Presence of zeros in the data |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
85 mat_corr <- function(data) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
86 cor(data) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
87 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
88 p_mat <- function(data) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
89 ggcorrplot::cor_pmat(data) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
90 } # compute a matrix of correlation p-values |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
91 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
92 graph_corr <- function(data_num) { |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
93 graph <- ggcorrplot::ggcorrplot(mat_corr(data_num), method = "circle", p.mat = p_mat(data_num), #barring the no significant coefficient |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
94 ggtheme = ggplot2::theme_gray, colors = c("#00AFBB", "#E7B800", "#FC4E07")) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
95 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
96 ggplot2::ggsave("0_pb.png", graph) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
97 } |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
98 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
99 ##Med and disp |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
100 med <- graph_median(data, var = colvar) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
101 disp <- dispersion(data, var = colvar, var2 = colspe) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
102 med_disp(med = med, disp = disp) |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
103 |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
104 ##O problem |
e5552099d0e3
"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff
changeset
|
105 graph_corr(data_num) |