annotate graph_homogeneity_normality.r @ 0:9f679060051a draft

"planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
author ecology
date Tue, 27 Jul 2021 16:56:15 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
1 #Rscript
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
2
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
3 #######################################
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
4 ## Homogeneity and normality ##
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
5 #######################################
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
6
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
7 #####Packages : car
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
8 # ggplot2
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
9 # ggpubr
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
10 # Cowplot
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
11
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
12 #####Load arguments
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
13
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
14 args <- commandArgs(trailingOnly = TRUE)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
15
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
16 if (length(args) == 0) {
9f679060051a "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")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
18 }else{
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
19 table <- args[1]
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
20 hr <- args[2]
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
21 date <- as.numeric(args[3])
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
22 spe <- as.numeric(args[4])
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
23 var <- as.numeric(args[5])
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
24 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
25
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
26 if (hr == "false") {
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
27 hr <- FALSE
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
28 }else{
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
29 hr <- TRUE
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
30 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
31
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
32 #####Import data
9f679060051a "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")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
34 data <- na.omit(data)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
35 coldate <- colnames(data)[date]
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
36 colspe <- colnames(data)[spe]
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
37 colvar <- colnames(data)[var]
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
38
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
39 #####Your analysis
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
40
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
41 ####Homogeneity of the variance####
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
42
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
43 ##Test of Levene##
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
44 testlevene <- function(data, col1, col2) {
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
45 data[, col1] <- as.numeric(data[, col1])
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
46 data[, col2] <- as.factor(data[, col2])
9f679060051a "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])
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
48
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
49 return(tb_levene)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
50 }
9f679060051a "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))
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
52
9f679060051a "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)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
54
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
55 ##Two boxplots to visualize it##
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
56
9f679060051a "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) {
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
58 data[, col1] <- as.factor(data[, col1])
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
59 if (mult) {
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
60 for (spe in unique(data[, col2])) {
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
61 data_cut <- data[data[, col2] == spe, ]
9f679060051a "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)) +
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
63 ggplot2::geom_boxplot() +
9f679060051a "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"),
9f679060051a "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"),
9f679060051a "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"))
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
67
9f679060051a "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")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
69 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
70 }else{
9f679060051a "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)) +
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
72 ggplot2::geom_boxplot() +
9f679060051a "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))
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
74
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
75 #Put multiple panels
9f679060051a "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") +
9f679060051a "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"),
9f679060051a "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"),
9f679060051a "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"))
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
80
9f679060051a "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")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
82 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
83 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
84
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
85 ####Normality of the distribution####
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
86 # Kolmogorov-Smirnov test
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
87
9f679060051a "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"))
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
89
9f679060051a "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)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
91
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
92 #Histogramm with distribution line
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
93 graph_hist <- function(data, var1) {
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
94 graph_hist <- ggplot2::ggplot(data) +
9f679060051a "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") +
9f679060051a "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") +
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
97 ggplot2::ggtitle("Distribution histogram")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
98
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
99 return(graph_hist)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
100 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
101
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
102 #Add the mean dashed line
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
103 add_mean <- function(graph, var1) {
9f679060051a "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]),
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
105 color = "midnightblue", linetype = "dashed", size = 1)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
106
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
107 return(graph_mean)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
108 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
109
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
110 #Adding a QQplot
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
111 graph_qqplot <- function(data, var1) {
9f679060051a "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")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
113
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
114 return(graph2)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
115 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
116
9f679060051a "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.
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
118
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
119 graph_fin <- function(graph1, graph2) {
9f679060051a "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)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
121
9f679060051a "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")
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
123 }
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
124
9f679060051a "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)
9f679060051a "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)
9f679060051a "planemo upload for repository https://github.com/Marie59/Data_explo_tools commit 2f883743403105d9cac6d267496d985100da3958"
ecology
parents:
diff changeset
127
9f679060051a "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)
9f679060051a "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)
9f679060051a "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))