I'm trying to add a significant level of boxplots in the form of stars using ggplot2 and package ggpubr , but I have a lot of comparison, and I just want to show meaningful.
I am trying to use the hide.ns = TRUE option in stat_compare_means , but it obviously does not work , it may be a bug in the ggpubr package .
In addition, you can see that I rule group "PGMC4" of pairwise comparisons wilcox.test ; how can i leave this group also for kruskal.test ?
Last question: how does significance level work? How is * significantly lower than 0.05, ** lower than 0.025, *** lower than 0.01? What convention does ggpubr use? Does p-value or adjusted p-value show? If the latter, what is the configuration method? Bh?
Please check my MWE below and this link and this other one for reference
set.seed(5)
mydf <- data.frame(ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000, 163, replace=FALSE), sep=''),
Group=c(rep('C',10),rep('FH',10),rep('I',19),rep('IF',42),rep('NA',14),rep('NF',42),rep('NI',15),rep('NS',10),rep('PGMC4',1)),
Value=rnorm(n=163))
groups <- as.character(unique(mydf$Group[which(mydf$Group!="PGMC4")]))
expand.grid.unique <- function(x, y, include.equals=FALSE){
x <- unique(x)
y <- unique(y)
g <- function(i){
z <- setdiff(y, x[seq_len(i-include.equals)])
if(length(z)) cbind(x[i], z, deparse.level=0)
}
do.call(rbind, lapply(seq_along(x), g))
}
combs <- as.data.frame(expand.grid.unique(groups, groups), stringsAsFactors=FALSE)
head(combs)
my.comps <- as.data.frame(t(combs), stringsAsFactors=FALSE)
colnames(my.comps) <- NULL
rownames(my.comps) <- NULL
my.comps <- as.list(my.comps)
head(my.comps)
pdf(file="test.pdf", height=20, width=25)
print(
ggplot(mydf, aes(x=Group, y=Value, fill=Group)) + geom_boxplot() +
stat_summary(fun.y=mean, geom="point", shape=5, size=4) +
scale_fill_manual(values=myPal) +
ggtitle("TEST TITLE") +
theme(plot.title = element_text(size=30),
axis.text=element_text(size=12),
axis.text.x = element_text(angle=45, hjust=1),
axis.ticks = element_blank(),
axis.title=element_text(size=20,face="bold"),
legend.text=element_text(size=16)) +
stat_compare_means(comparisons=my.comps, method="wilcox.test", label="p.signif", size=14) +
stat_compare_means(method="kruskal.test", size=14)
)
dev.off()
MWE will create the following squares:

Questions:
1 How to make hide.ns = TRUE work?
2- How to increase size *?
3 How to exclude a group from kruskal.test comparison?
4- What is the * convention used by ggpubr and are the p values indicated, edited or not?
Many thanks!
EDIT
In addition, when performing
stat_compare_means(comparisons=my.comps, method="wilcox.test", p.adjust.method="BH")
I do not get the same p values as when doing
wilcox.test(Value ~ Group, data=mydf.sub)$p.value
where mydf.sub is a subset () of mydf for this comparison of the two groups.
ggpubr? p.values?
2
, , ggpubr ( ggplot2), NS , p-, wilcox.test() + p.adjust( "BH" ).
!