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