Hi, I am wondering if anyone can help me with my codes in adding significant letters of the Tukey test to the boxplot.
I have four locations and for each I have a sampling side. So I want to add the significant letter of the statistical test on each boxplot of the side per location. But I am missing something, because it just duplicates the letters for each side per location in the chart, but not in each box for each site. So can someone help me how to separate them? And I am trying to apply group= side, but then I do not get charts per location. Thanks in advance
My codes:
alpha_test_letters_location<-ddply(alpha_test_location,.(measure, side),function(x) {
data.frame(letters=multcompLetters(setNames(x$pval,x$location_pairs))$Letters) %>%
rownames_to_column("location") %>%
mutate(letters=if(length(levels(letters))==1){mapvalues(letters,levels(letters),NA)} else{letters})
}) %>%
mutate(location=as.factor(location)) %>%
full_join(alpha_phylo_df) %>%
group_by(measure, side) %>%
mutate(pos=max(value)*1.06)
plot_alpha_letters<-ggplot(alpha_phylo_df,aes(x=location,y=value)) +
geom_boxplot(aes(fill=location, alpha=side))+
geom_text(data= alpha_test_letters_location, aes(label=letters, x=location, y=pos),vjust=2,hjust= 0, size=4) +
#geom_text(data=alpha_test_letters_side,aes(x=location,y=pos,label=letters),vjust=0.85,size=5,inherit.aes=F)
facet_wrap(~measure,nrow=2,scales="free_y") +
labs(y="value",fill="location")+
scale_alpha_manual(values=c(0.4,1)) +
theme_classic()+
theme(#legend.position=c(0.85,0.2),
#legend.box="horizontal",
legend.text = element_text(size=12),
strip.text.x = element_text(size = 12, face = "bold"),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x=element_blank(),
axis.text.y=element_text(size=12, face="bold"),
axis.title.y = element_text(size = 14))