ggboxplot - add p-value in the boxplot

how to add the p value onto basic ggplots.

see reference: https://www.datanovia.com/en/blog/how-to-add-p-values-onto-basic-ggplots/

library(Jerry)
#> Loading required package: tidyverse
#> Warning: package 'tidyverse' was built under R version 4.0.5
#> -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
#> v ggplot2 3.3.3     v purrr   0.3.4
#> v tibble  3.1.1     v dplyr   1.0.6
#> v tidyr   1.1.3     v stringr 1.4.0
#> v readr   1.4.0     v forcats 0.5.1
#> Warning: package 'ggplot2' was built under R version 4.0.5
#> Warning: package 'tibble' was built under R version 4.0.5
#> Warning: package 'tidyr' was built under R version 4.0.5
#> Warning: package 'readr' was built under R version 4.0.3
#> Warning: package 'forcats' was built under R version 4.0.5
#> -- Conflicts ------------------------------------------ tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag()    masks stats::lag()
#> Warning: replacing previous import 'ggplot2::annotate' by 'ggpmisc::annotate'
#> when loading 'Jerry'
library(ggpubr)
library(rstatix)
#> 
#> Attaching package: 'rstatix'
#> The following object is masked from 'package:stats':
#> 
#>     filter

data(signatures)

head(signatures)
#>   Tumor_Sample_Barcode Signature.1 Signature.6 Signature.17 Signature.15
#> 1           M01_1D_Aca    0.000000    3.660088    0.0000000     0.000000
#> 2           M03_1A_Aca   57.638866    0.000000    1.3355527    20.316812
#> 3           M03_1B_Aca   44.026712    3.300601    0.0000000    18.114416
#> 4           M03_1C_Aca   43.686315   15.573550    0.2367439     4.903536
#> 5           M03_1D_Aca   55.881582   15.169653    0.3350532    11.077736
#> 6          M04_11H_Aca    9.724408    0.000000    0.0000000     6.571080
#>   Signature.3 mutNum sig6     group
#> 1     9.20233     13 noS6 Aca.early
#> 2     0.00000     74 noS6 Aca.early
#> 3     0.00000     62 noS6 Aca.early
#> 4     0.00000     64   S6 Aca.early
#> 5     0.00000     80   S6 Aca.early
#> 6    33.81792     51 noS6 Aca.early

#non-params test: wilcox_test
wilcox.test = signatures  %>%
  group_by(group) %>%
  wilcox_test(mutNum ~ sig6) %>%
  add_xy_position(x = "sig6", fun = "mean_sd" ) %>%
  add_significance("p")


signatures %>%
  ggboxplot(
            x = "sig6", y = "mutNum", col = "sig6",
            facet.by = "group", scales = "free",
            xlab = "signature 6", ylab = "# muts",
            add = "jitter", add.params = list(width = 0.1, size = 1, shape = 1) ,
            ggtheme = theme_classic()) +
  stat_pvalue_manual(wilcox.test, label = "p") +
  guides(color = "none"  )



signatures %>%
  ggboxplot(
            x = "sig6", y = "mutNum", col = "sig6",
            facet.by = "group", scales = "free",
            xlab = "signature 6", ylab = "# muts",
            add = "jitter", add.params = list(width = 0.1, size = 1, shape = 1) ,
            ggtheme = theme_classic()) +
  stat_pvalue_manual(wilcox.test, label = "p.signif") +
  guides(color = "none"  )