Asking help in adding significant letter of Tukey test to boxplot

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))

The code needs some data to go with it. See the FAQ: How to do a minimal reproducible example reprex for beginners.

Thanks for your answer I will see your recommendation.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.