Hi folks! I need your help with a ggplot2 representation.

I have a data set that has the following structure: 

    log2FoldChange      Sequence_biotype      Knockdown     
    -1.40               LTR                   A 
    -1.11               DNA                   B
    -3.46               Protein               A
    -1.25               Protein               C
     1.03               DNA                   B
     ...                ...                   ... 

I am plotting the foldChanges as boxplots, one for each `Sequence_biotype`. I have the knockdown variable faceted.
What I'm trying to do is to do a one sample Wilcoxon test for each boxplot, comparing the log2FoldChange to 0 (to see if there is a significant change). That can be achieved with the following code:

`wilcox.test(x = data, mu = 0)`

when the data is grouped by Sequence_biotype and Knockdown.

My question is, how could I introduce the results of the wilcox test to the plot as labels or how could I compute it directly in the plot (I have been trying with `stat_compare_means(method = "wilcox", paired = FALSE)` from ggpubr package but all the pvalues are piling up to the same spot)

Thank you before hand, any help is appreciated!

Best,

Jordi
In case anyone faces the same problem, I will paste the code I used to get the plot.

    # Subset the dataset into different knockdowns
    A = com_sig.df[com_sig.df$Knockdown=="A",]
    B = com_sig.df[com_sig.df$Knockdown=="B",]
    C = com_sig.df[com_sig.df$Knockdown=="C",]
    
    # Compute the test for the first knockdown and the position in the plot
    stat.test_A = compare_means(log2FoldChange ~ 1, paired = FALSE, data = A, method = "wilcox.test", 
                              group.by = "Sequence_biotype", mu = 0) %>%
                     mutate(y.position = 4.5)
    
    # Add a label to identify the knockdown
    stat.test_A$Knockdown = "A"
    
    # Same for second knockdown
    stat.test_B = compare_means(log2FoldChange ~ 1, paired = FALSE, data = B, method = "wilcox.test", 
                              group.by = "Sequence_biotype", mu = 0) %>%
                     mutate(y.position = 4.5)
    stat.test_B$Knockdown = "B"
    
    # Same for the third one
    stat.test_C = compare_means(log2FoldChange ~ 1, paired = FALSE, data = C, method = "wilcox.test", 
                              group.by = "Sequence_biotype", mu = 0) %>%
                     mutate(y.position = 4.5)
    stat.test_C$Knockdown = "C"
    
    # Combine all 3 datasets into 1
    stat.test = do.call(rbind, list(stat.test_A, stat.test_B, stat.test_C))
    
    # change column name of the variable used to compute the wilcox test
    names(stat.test)[names(stat.test)==".y."] = "log2FoldChange"
    
    com = ggboxplot(data  = com_sig.df, x = "Sequence_biotype", y = "log2FoldChange", fill = "Sequence_biotype",
                     facet.by = "Knockdown") +
          geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
          theme_bw() +
          theme(legend.position = "none",
                axis.title.x = element_text(hjust = .975, vjust = -.6),
                plot.title = element_text(hjust = .5),
                axis.text.x = element_blank(),
                strip.background = element_blank(),
                strip.text.x = element_blank()) +
          geom_text(data = stat.test, aes(y=y.position,label = p.signif))
    com

[Plot Generated][1]


  [1]:https://ibb.co/hXY4rbT