What I would like to do is add the Tukey letters to this ggplot.
My plot:
I've tried by doing the tukey analysis first, then adding it to ggplot but that just doesn't work with the facet grid
value_max4 = salix2 %>% group_by(Treat) %>% summarize(max_value = max(`PO4_(ug/g)`))
hsd4=HSD.test(aov(`PO4_(ug/g)`~Treat, data=salix2), trt = "Treat", group = T)
sig.letters4 <- hsd4$groups[order(row.names(hsd4$groups))
P04SA <- salix%>%
ggplot(salix, mapping=(aes( y= `PO4_(ug/g)`, x = Treat))) +
geom_text(data = value_max4, aes(x=Treat, y = 0.1 + max_value4, label = sig.letters4$groups), vjust=0)+
facet_grid(cols = vars(depth), scales = "free", labeller = label_both) +
geom_boxplot()+theme(text = element_text(size = 15))+
stat_summary(fun = mean, shape = 5, color= "black", position = position_dodge(0.75))+
labs( x= "Treatment", y= "Phosphate (ug/g) "
,caption="Control (C), Long Growing Season (LG), Shading (S), Short Growing Season (SG), Increase Growing Season Temperature (T)"
,alt = "Diamond represents the mean")
P04SA
My aim is once i've added the tukey test to each graph to then use ggarrange to get one big graph
bip <- ggarrange(N03sa, NH4SA, P04SA,
ncol= 1,
labels = c("A", "B", "C"))
bip
any help would be very much appreciated