Hi,
Thank you for you answer.
Yes it works but the solution for me that I finally found with some help is to generate For() loops with vectors in which I stock my different variables to specifically do the Tukey test to one variety per variety and do the Tukey test inside the loop.
I have in my dataset two groups of data:
Inoc and mock, the same 4 varieties tested in the two groups and for each variety, the same 4 treatments like simply presented juste above and for everyone, I want to do the tukey test with meny outcomes (my different measures for each one) this and there is the code for this.
Inoc
var1: Trt1, Trt2, Trt3, Trt4
var2: Trt1, Trt2, Trt3, Trt4
var3: Trt1, Trt2, Trt3, Trt4
var4 : Trt1, Trt2, Trt3, Trt4
Mock
var1: Trt1, Trt2, Trt3, Trt4
var2 : Trt1, Trt2, Trt3, Trt4
var3 : Trt1, Trt2, Trt3, Trt4
var4 : Trt1, Trt2, Trt3, Trt4
graphes = NULL
dt = NULL
for (inoc in c("Inoc", "Mock")) {
graphes[[inoc]] = NULL
dt [[inoc]] = NULL
#outcome is for exemple the weight of the plants, the length that I want to explain in my linear model
for (var_name in c("Outcome1", "Outcome2", "Outcome3")) {
graphes[[var_name]] = NULL
dt[[var_name]] = NULL
for (espece in c("Var1","Var2","Var3","Var4")) {
tab = filter(dt2, Variété==espece, Inoc==inoc)
anova = aov(get(var_name) ~ Traitement, data = tab)
# Tukey's test
tukey = TukeyHSD(anova)
# compact letter display
cld = multcompLetters4(anova, tukey)
.
.
.
graph = ggplot(dt, aes(Traitement, w)) +
.
.
.
graphes[[inoc]] [[var_name]] [[espece]]= graph
}
}
}
and then another loop to generate the graphes
library(gridExtra)
for (inoc in c("Inoc","Mock")) {
for (var_name in c("Outcome1", "Outcome2", "Outcome3")) {
grid.arrange(graphes[[inoc]] [[var_name]] [["Var1"]],
graphes[[inoc]] [[var_name]] [["Var2"]],
graphes[[inoc]] [[var_name]] [["Var3"]],
graphes[[inoc]] [[var_name]] [["Var4"]],
nrow=2, ncol=2, top=paste(var_name,inoc))
}
}
I show only two but with grid.arrange I obtain four graphes (1 per variety) with Tukey test inside a variety only, not all the varieties in the same time as in the first image of the post. And I obtain the graphes for all my outcomes for Inoc and Mock to my 4 varieties in each.
I hope it'll help because I never found the entire answer to my problem 