const-ae / ggsignif

Easily add significance brackets to your ggplots
https://const-ae.github.io/ggsignif/
GNU General Public License v3.0
593 stars 43 forks source link

Adding significance bar on coupled boxplots #132

Open Lucas97223 opened 1 year ago

Lucas97223 commented 1 year ago

I have trying to put significance bars on my group boxplots but I cannot find a way. What I have for the moment is the following:

`A <- c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24)

B <- c(104.125,120.125,158.125,149.750,146.750,137.125,146.500,150.125,153.375,163.000,144.125,163.625,167.875,163.250,167.500,180.000,153.500,127.250,147.000,120.125,122.750,108.000,111.000,,64.250)

C <- c(84.625,113.625,120.875,133.750,134.125,139.875,129.625,127.125,137.125,128.375,143.250,146.125,156.000,140.625,154.875,160.125,174.000,185.000,174.750,183.125,167.000,153.875,132.750,102.375)

distrib_df <- data.frame(animal=c(rep(“a1”,192),rep(“a2”,192)), bins=as.factor(A), each_vids=c(B,C)) max_y <- quantile(distrib_df[[3]],c(0.99))[[1]] plot_distrib <- ggplot(data=distrib_df,aes(x=bins, y=each_vids, fill=animal)) + geom_boxplot() + geom_point(position=position_jitterdodge(),col=c(rep("red",(length(listbins)-correction)8),rep("blue",(length(listbins)-correction)8))) + labs(x="Time bins", y=label_y) + ylim(0,max_y+0.2*max_y).`

Which gives me the output you can see below

image

I now want to put significance bar over each pair of boxplot. I have tried the following, for only the two first to see if it worked but it does not...

plot_distrib + geom_signif(stat="identity", data=data.frame(x=c(0.875,1.875), xend=c(1.125,2.125), y=rep(max_y,2), annotation=c("MY","ASS")), aes(x=x, xend=xend, y=y, yend=y, annotation=annotation))

But this gives me the error message that I do not know how to solve.

image

Thanks by advance for your help!