GGPUBR: How to Add P-Values Generated Elsewhere to a GGPLOT
This article describes how to add p-values generated elsewhere to a ggplot using the ggpubr package. The following key ggpubr functions will be used:
stat_pvalue_manual(): Add manually p-values to a ggplot, such as box blots, dot plots and stripcharts.
geom_bracket(): Add brackets with label annotation to a ggplot. Helpers for adding p-value or significance levels to a plot.
You will learn how to:
Add custom p-values created from elsewhere
Add p-values obtained from the rstatix R package
Add brackets with custom p-value labels to a ggplot
Make sure you have the following R packages:
tidyverse for data manipulation and visualization
ggpubr for creating easily publication ready plots
rstatix provides pipe-friendly R functions for easy statistical analyses
Load required R packages:
Add p-values computed from elsewhere
Key R function: stat_pvalue_manual() [in ggpubr package]
stat_pvalue_manual(data, label = NULL)
Add p-values obtained from the rstatix package Create a simple box plot
Pairwise comparisons
Faceted Plots
Grouped plots
Specify manually the y position of the p-values
Create a simple box plot:
Faceted plots: Comparisons between two groups
Faceted Plot: Pairwise comparissons between multiple groups
Grouped plots
Add brackets with custom p-value labels to a ggplot
This section describes the function geom_bracket() [in ggpubr package] for adding brackets with label annotation to a ggplot. It makes it easy to add p-value or significance levels created elsewhere to a plot. Basic brackets with labels
Using plotmath expression and specifying multiple brackets manually
Compute statistical test and add p-values ::: {.cell autorun=‘true’}
:::