how to add multicompletters for significance on box plot

Hi,

Could anyone please help me how to add letters of significance when plotting multiple box plot?
Here I have got multiple box and their corresponding significance letters but not sure how to add like cld1, cld2.....to the box plot in ggplot.

library(reshape2)
library(ggplot2)
library(multcompView)
library(tidyverse)
library(dplyr)
list.files()

bpdata <- read.table("species.updated.txt", sep="\t", header=TRUE)
str(bpdata)
dput(bpdata)


bpdata[,"SampleType"] <- as.factor(bpdata[,"SampleType"])
bpdata <- cbind(row.names(bpdata),bpdata)
names(bpdata)[1] <- "sample"


########################################################

#for posthoc test

model=lm(P ~ SampleType, bpdata)
anova1=aov(model)
summary(anova1)




tukey1 <-TukeyHSD(anova1)
print(tukey1)

####################
cld1 <-multcompLetters4(anova1,tukey1)
print(cld1)


####################################################

#for posthoc test

model=lm(Ca ~ SampleType, bpdata)
anova2=aov(model)
summary(anova2)




tukey2 <-TukeyHSD(anova2)
print(tukey2)

####################
cld2 <-multcompLetters4(anova2,tukey2)
print(cld2)






############################################################
pdf("rice.grain.pdf", width = 18, height = 8)

ncol=3
p <- ggplot(data = data, aes(x="", y=value,fill= SampleType)) +
theme_bw() +
theme(
      panel.grid.major=element_blank(),
      panel.grid.minor=element_blank(),
      plot.title = element_text(vjust = -8.5,hjust = 0.1),
      line=element_line(size=1), 
      
      
      axis.text.x = element_text(size = 10, face ="bold.italic", hjust = 0.5, colour = "black", angle = 90),
      axis.text.y = element_text(size = 12, face ="bold", hjust = 0.5, colour = "black"),title =element_text (size=16,face="bold"),
      axis.ticks.x = element_blank()) +

theme(legend.text=element_text(size=14)) +
theme(strip.background=element_rect(fill="white")) +
theme(strip.text=element_text(color="black",face="bold", size =14)) +
theme(strip.background=element_rect(fill="grey90", colour="grey50"))+
geom_boxplot(aes(fill=SampleType),outlier.colour = NA) 
p + facet_wrap(.~name,scales="free_y", ncol = ncol) 
dev.off();

Thank you so much. I have sorted this issue.

Many thanks,
Yogesh

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.