annotate graph_homogeneity_normality.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
1 #Rscript
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
2
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
3 #######################################
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
4 ## Homogeneity and normality ##
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
5 #######################################
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
6
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
7 #####Packages : car
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
8 # ggplot2
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
9 # ggpubr
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
10 # Cowplot
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
11
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
12 #####Load arguments
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
13
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
14 args <- commandArgs(trailingOnly = TRUE)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
15
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
16 if (length(args) == 0) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
17 stop("This tool needs at least one argument")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
18 }else{
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
19 table <- args[1]
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
20 hr <- args[2]
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
21 date <- as.numeric(args[3])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
22 spe <- as.numeric(args[4])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
23 var <- as.numeric(args[5])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
24 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
25
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
26 if (hr == "false") {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
27 hr <- FALSE
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
28 }else{
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
29 hr <- TRUE
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
30 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
31
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
32 #####Import data
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
33 data <- read.table(table, sep = "\t", dec = ".", header = hr, fill = TRUE, encoding = "UTF-8")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
34 data <- na.omit(data)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
35 coldate <- colnames(data)[date]
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
36 colspe <- colnames(data)[spe]
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
37 colvar <- colnames(data)[var]
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
38
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
39 #####Your analysis
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
40
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
41 ####Homogeneity of the variance####
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
42
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
43 ##Test of Levene##
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
44 testlevene <- function(data, col1, col2) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
45 data[, col1] <- as.numeric(data[, col1])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
46 data[, col2] <- as.factor(data[, col2])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
47 tb_levene <- car::leveneTest(y = data[, col1], group = data[, col2])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
48
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
49 return(tb_levene)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
50 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
51 levene <- capture.output(testlevene(data = data, col1 = colvar, col2 = colspe))
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
52
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
53 cat("\nwrite table with levene test. \n--> \"", paste(levene, "\"\n", sep = ""), file = "levene.txt", sep = "", append = TRUE)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
54
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
55 ##Two boxplots to visualize it##
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
56
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
57 homog_var <- function(data, col1, col2, col3, mult) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
58 data[, col1] <- as.factor(data[, col1])
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
59 if (mult) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
60 for (spe in unique(data[, col2])) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
61 data_cut <- data[data[, col2] == spe, ]
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
62 graph_2 <- ggplot2::ggplot(data_cut, ggplot2::aes_string(x = col1, y = col3, color = col1)) +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
63 ggplot2::geom_boxplot() +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
64 ggplot2::theme(legend.position = "none", axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust = 1), panel.background = ggplot2::element_rect(fill = "#d9d4c5", colour = "#d9d4c5", linetype = "solid"),
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
65 panel.grid.major = ggplot2::element_line(linetype = "solid", colour = "white"),
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
66 panel.grid.minor = ggplot2::element_line(linetype = "solid", colour = "white"))
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
67
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
68 ggplot2::ggsave(paste("Homogeneity_of_", spe, ".png"), graph_2, width = 16, height = 9, units = "cm")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
69 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
70 }else{
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
71 graph_1 <- ggplot2::ggplot(data, ggplot2::aes_string(x = col1, y = col3, color = col1)) +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
72 ggplot2::geom_boxplot() +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
73 ggplot2::theme(legend.position = "none", axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust = 1))
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
74
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
75 #Put multiple panels
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
76 graph_2 <- graph_1 + ggplot2::facet_grid(rows = ggplot2::vars(data[, col2]), scales = "free") +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
77 ggplot2::theme(panel.background = ggplot2::element_rect(fill = "#d9d4c5", colour = "#d9d4c5", linetype = "solid"),
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
78 panel.grid.major = ggplot2::element_line(linetype = "solid", colour = "white"),
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
79 panel.grid.minor = ggplot2::element_line(linetype = "solid", colour = "white"))
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
80
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
81 ggplot2::ggsave("Homogeneity.png", graph_2, width = 16, height = 9, units = "cm")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
82 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
83 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
84
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
85 ####Normality of the distribution####
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
86 # Kolmogorov-Smirnov test
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
87
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
88 ks <- capture.output(ks.test(x = data[, var], y = "pnorm", alternative = "two.sided"))
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
89
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
90 cat("\nwrite table with Kolmogorov-Smirnov test. \n--> \"", paste(ks, "\"\n", sep = ""), file = "ks.txt", sep = "", append = TRUE)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
91
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
92 #Histogramm with distribution line
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
93 graph_hist <- function(data, var1) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
94 graph_hist <- ggplot2::ggplot(data) +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
95 ggplot2::geom_histogram(ggplot2::aes_string(x = var1), binwidth = 2, color = "black", fill = "white") +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
96 ggplot2::geom_density(ggplot2::aes_string(var1), alpha = 0.12, fill = "red") +
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
97 ggplot2::ggtitle("Distribution histogram")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
98
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
99 return(graph_hist)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
100 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
101
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
102 #Add the mean dashed line
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
103 add_mean <- function(graph, var1) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
104 graph_mean <- graph + ggplot2::geom_vline(xintercept = mean(data[, var1]),
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
105 color = "midnightblue", linetype = "dashed", size = 1)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
106
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
107 return(graph_mean)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
108 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
109
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
110 #Adding a QQplot
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
111 graph_qqplot <- function(data, var1) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
112 graph2 <- ggpubr::ggqqplot(data, var1, color = "midnightblue") + ggplot2::ggtitle("Q-Q plot")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
113
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
114 return(graph2)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
115 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
116
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
117 #On suppose que les données sont distribuées normalement lorsque les points suivent approximativement la ligne de référence à 45 degrés.
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
118
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
119 graph_fin <- function(graph1, graph2) {
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
120 graph <- cowplot::plot_grid(graph1, graph2, ncol = 2, nrow = 1)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
121
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
122 ggplot2::ggsave("Normal_distribution.png", graph, width = 10, height = 7, units = "cm")
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
123 }
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
124
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
125 mult <- ifelse(length(unique(data[, colspe])) == 2, FALSE, TRUE)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
126 homog_var(data, col1 = coldate, col2 = colspe, col3 = colvar, mult = mult)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
127
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
128 graph_hist1 <- graph_hist(data, var1 = colvar)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
129 graph_mean <- add_mean(graph = graph_hist1, var1 = colvar)
fb7b2cbd80bb "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 60627aba07951226c8fd6bb3115be4bd118edd4e"
ecology
parents:
diff changeset
130 graph_fin(graph1 = graph_mean, graph2 = graph_qqplot(data, var1 = colvar))