I made a ggplot with my data. than I wanted to label some interactions between my boxplot-data (via anova/Tukey) to show, if there are signifikant differences between special Groups or not. I'm working with one csv-sheet called "test", that I have imported and with one tabel called "final"
[
[
but when I plot my data WITH the label from my TukeyHSD, I get every label triple with empty spaces.
how can i remove the empty spaces. there must be any solution to just show the first tree lines with label in the first plot, the middle tree lines in the middle plot with their specific label and the last tree lines in the third spot with label. How can I remove those empty lines with their alphateic labels?
Here my code:
test$int<-interaction(test$geno,test$n)
generate_label_df <- function(TUKEY, variable){
Tukey.levels <- TUKEY[[variable]][,4]
Tukey.labels <- data.frame(multcompLetters(Tukey.levels)['Letters'])
Tukey.labels$int=rownames(Tukey.labels)
Tukey.labels=Tukey.labels[order(Tukey.labels$int) , ]
return(Tukey.labels)
}
model=lm(test$amino~test$int ) ###
ANOVA=aov(model)
TUKEY <- TukeyHSD(x=ANOVA, 'test$int', conf.level=0.95)
labels<-generate_label_df(TUKEY , "test$int")
names(labels)<-c('Letters','int')
yvalue<-aggregate(amino~int, data=test, max)
final<-merge(labels,yvalue)
ggplot(test, aes(x=int, y=amino)) +
stat_boxplot(geom="errorbar") +
geom_boxplot(aes(fill=CO2)) +
geom_text(data = final, aes(label = Letters, vjust = -0.6)) +
labs(title = "Aminosäuren Erdkultur", x = "Genotyp", y = "Aminosäurekonz. [µmol/gFW]") +
scale_x_discrete(labels = c("col.Ammonium" = "col", "sps.Ammonium" = "sps",
"swe.Ammonium" = "swe", "col.Nitrat" = "col",
"sps.Nitrat" = "sps", "swe.Nitrat" = "swe",
"col.NON" = "col", "sps.NON" = "sps","swe.NON" = "swe"),
limits = c("col.Ammonium", "sps.Ammonium", "swe.Ammonium",
"col.Nitrat", "sps.Nitrat","swe.Nitrat", "col.NON",
"sps.NON", "swe.NON") )+
guides(fill = guide_legend(title = "CO2-Behandlung")) +
theme(plot.title = element_text(face = "bold", size="17", hjust = "0.5")) +
scale_fill_manual(values = c("violetred3", "steelblue1")) +
facet_wrap( ~ n) +
theme(legend.title = element_text(face = "bold"))
my first opinion was, to remove "facet_wrap(~n)". The Problem is solved than, but obviously I'm missing the subdivision on this way