Following up on this question I posted some days ago, I want to perform something similar.
Given the following MWE:
##############################
##MWE
library(ggplot2)
library(ggsignif)
set.seed(1)
alpha.subA <- data.frame(Sample.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))
alpha.subA$DB <- "DATABASE1"
set.seed(2)
alpha.subB <- data.frame(Sample.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))
alpha.subB$DB <- "DATABASE2"
alpha.sub <- rbind(alpha.subA, alpha.subB)
alpha.sub$DB <- as.factor(alpha.sub$DB)
alpha.sub$both <- factor(paste(alpha.sub$Group, alpha.sub$DB), levels=paste(rep(levels(alpha.sub$Group), each=length(levels(alpha.sub$DB))), rep(levels(alpha.sub$DB), length(levels(alpha.sub$Group)))))
png(filename="test.png", height=1000, width=2000)
print(#or ggsave()
ggplot(alpha.sub, aes(x=both, y=Value, fill=Group)) + geom_boxplot() +
facet_grid(~Group, scales="free", space="free_x") +
stat_summary(fun.y=mean, geom="point", shape=5, size=4)
# + geom_signif() ##HOW TO TEST EACH PAIR IN EACH FACET (DATABASE1 vs DATABASE2 PER GROUP)?
)
dev.off()
##############################
which produces:
I would like to make use of ggsignif's geom_signif() to compare DATABASE1 to DATABASE2 per Group (each pair in a facet) and show the significance level (* for p-value<0.05, ** for p-value<0.01) for each pairwise comparison.
Any help would be greatly appreciated. Thanks!!
Aucun commentaire:
Enregistrer un commentaire