annotate graph_homogeneity_normality.r @ 0:c7dd4706f982 draft

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