Written and maintained by CASRAI Editorial Board
Published
On this page
ggpubr is an R package, written and maintained by Alboukadel Kassambara, that wraps ggplot2 in short functions for common research figures (box plots, violin plots, scatter plots, bar plots, density plots) and adds statistical annotations such as p-values to them. CRAN describes it as providing ‘easy-to-use functions for creating and customizing ggplot2-based publication ready plots’. You install it with install.packages("ggpubr"), load it with library(ggpubr), and typically draw a plot with ggboxplot() and add a test result with stat_compare_means().
What ggpubr is used for in research
ggplot2 is flexible, but its default output usually needs formatting before it goes into a manuscript, and its syntax is opaque for researchers with little programming background. The ggpubr package description on CRAN names exactly this gap: it provides functions that create and customize ggplot2-based plots so that the figure needs less hand-tuning before submission. Because every ggpubr plot is still a ggplot object, you can keep adding ordinary ggplot2 layers, themes and scales afterwards.
The reference manual shows the package’s main plotting functions: ggboxplot(), ggviolin(), ggscatter(), ggbarplot(), ggpaired(), ggqqplot(), plus ggarrange() for placing several figures on one page, ggpar() for graphical parameters and ggexport() for writing plots to files. Box plots, violin plots and bar plots take an add argument that overlays another element on the same plot; for ggboxplot() the allowed values include "jitter", "dotplot", "point", "mean", "mean_se", "mean_sd", "mean_ci", "median" and "median_iqr". The default theme for these functions is theme_pubr(), which is why the output looks cleaner than a bare ggplot2 call.
The second reason researchers use ggpubr is statistical annotation. stat_compare_means() adds a mean-comparison p-value to a box plot, dot plot or stripchart; compare_means() returns the same comparisons as a table; geom_pwc() adds pairwise comparisons with multiple-testing adjustment; and stat_pvalue_manual() places p-values you computed elsewhere onto a figure. Version 1.0.0, published on CRAN on 2026-07-06, also added p-value formatting presets (APA, AMA, NEJM, Lancet, GraphPad and scientific notation) so the labels can follow a journal’s reporting style.
ggpubr draws annotations; it is not a replacement for choosing a test. If you only need brackets, the ggsignif package (see ggsignif) provides a single layer for that, and ggpubr itself imports it for the brackets drawn when comparisons is used. Related helpers covered elsewhere on CASRAI include ggarrange for multi-panel figures and ggrepel for non-overlapping labels.
How to install or access ggpubr
Install ggpubr from CRAN, the official R package repository, in an R session:
- Check your versions. CRAN lists ggpubr 1.0.0 as depending on R 4.1.0 or later and ggplot2 3.5.2 or later. Run
R.version.stringandpackageVersion("ggplot2")to see what you have. - Run
install.packages("ggpubr"). Its imports on CRAN include ggrepel, ggsci, tidyr, purrr, dplyr, cowplot, ggsignif, gridExtra, glue, polynom, rlang, rstatix, tibble and magrittr, and R’s package installer fetches the ones you do not already have. - Load it with
library(ggpubr). Loading ggpubr also attaches ggplot2 as a dependency.
Two other official routes exist. The development version is installed from GitHub with devtools::install_github("kassambara/ggpubr"), as given on the package’s documentation site at rpkgs.datanovia.com/ggpubr. For conda users, the conda-forge package page gives conda install conda-forge::r-ggpubr, and lists version 1.0.0 under the GPL-2.0-only license. CRAN lists the license as GPL-2 or GPL-3. Cite the package using its CRAN DOI, 10.32614/CRAN.package.ggpubr, and report the version you used in your methods section.
How to add p-values to a box plot with ggpubr step by step
This worked example follows the reference manual’s own examples, which use ToothGrowth, a dataset that ships with R. It has a numeric response len, a grouping variable supp with two levels, and a dose variable with three levels. Because it is built in, anyone can reproduce your figure. Run each step in order.
- Load the package and the data:
library(ggpubr)anddata("ToothGrowth"). - Draw a box plot for two independent groups, with jittered points on top and the npg palette:
p = ggboxplot(ToothGrowth, x = "supp", y = "len", color = "supp", palette = "npg", add = "jitter"). - Add the test result:
p + stat_compare_means(). The p-value appears at the top left of the panel by default. - Change the test if your design needs a different one:
p + stat_compare_means(method = "t.test"). Themethodargument takes the name of the test;method.argspasses extra arguments, for examplemethod.args = list(alternative = "greater")for a Wilcoxon test. - For paired data, draw with
ggpaired()and setpaired = TRUE:ggpaired(ToothGrowth, x = "supp", y = "len", color = "supp", line.color = "gray", line.size = 0.4, palette = "npg") + stat_compare_means(paired = TRUE). If your rows are not sorted so that the two groups line up by subject, add an identifier column and passid = "id"; the manual states that without it the paired test pairs observations by row order, so the p-value is wrong when the data are not sorted. - For more than two groups, list the pairs you want with
comparisonsand add a global test:my_comparisons = list(c("0.5", "1"), c("1", "2"), c("0.5", "2")), thenggboxplot(ToothGrowth, x = "dose", y = "len", color = "dose", palette = "npg") + stat_compare_means(comparisons = my_comparisons, label.y = c(29, 35, 40)) + stat_compare_means(label.y = 45). Thelabel.yvalues place each bracket and the global label in data units so they do not overlap. - Report the p-value in your journal’s style by setting
p.format.styleto one of"apa","nejm","lancet","ama","graphpad"or"scientific". Further arguments (p.digits,p.leading.zero,p.min.threshold,p.decimal.mark) override the style’s defaults. - Tune the look with
ggpar(), for exampleggpar(p, palette = "jco"),ggpar(p, ylim = c(0, 50))orggpar(p, yscale = "log2"), and combine panels withggarrange(bxp, dp, common.legend = TRUE). - Write the figure to disk with
ggexport(filename = "test.pdf")orggexport(filename = "test.png"), as shown in the manual’s examples.
The data table below summarises which ggpubr annotation function applies which test and which adjustment by default, taken from the reference manual.
How to read the output
With the defaults, stat_compare_means() prints a label made of the test name and the p-value, separated by label.sep (default “, “). You can change what is shown with the label argument: "p.signif" shows significance symbols, "p.format" shows the formatted p-value, and "p.format.signif" shows the formatted p-value followed by stars.
Significance symbols
The manual states the default convention: ns (not significant) means p above 0.05, one star means p ≤ 0.05, two stars mean p ≤ 0.01, three stars mean p ≤ 0.001 and four stars mean p ≤ 0.0001. Four stars appear in the default convention only when the cutoffs allow them; you can replace the cutoffs and symbols with signif.cutoffs and signif.symbols, and if signif.cutoffs is given it takes precedence over symnum.args. hide.ns = TRUE hides the “ns” label, and ns.symbol = "" shows nothing for non-significant results.
Which p-values are adjusted
This is the point most readers miss. The manual notes that when comparisons is specified in stat_compare_means(), each pairwise test is computed independently and the displayed p-values are not adjusted for multiple comparisons. For adjusted p-values it points to geom_pwc(), or to stat_pvalue_manual() together with compare_means(..., p.adjust.method = ). compare_means() and geom_pwc() both default to p.adjust.method = "holm". If you report several brackets drawn with comparisons, state in the figure legend whether the values are adjusted. For post hoc comparisons after an ANOVA, see the guide to Tukey’s test in R.
Choosing between parametric and non-parametric tests
For compare_means() the manual lists t.test and wilcox.test for two groups (a pairwise comparison is performed when there are more than two levels), and anova and kruskal.test for one-way tests across several groups, with wilcox.test as the default. ggpubr will run whichever test you name, so the choice must come from your design and data. Document it in your methods text; the figure label shows the test name, but a reader will still look for the reasoning.
Troubleshooting ggpubr
Installation fails or the package will not load
Check the version requirements first. CRAN’s ggpubr 1.0.0 depends on R 4.1.0 or later and ggplot2 3.5.2 or later, and several imports (dplyr 1.2.0, cowplot 1.2.0, rstatix 1.0.0, tidyr 1.3.2) carry minimum versions. On an older R, the installer cannot satisfy these and you should upgrade R rather than force the install. In a container or on a managed server where you cannot upgrade, the conda route above installs from conda-forge, which provides version 1.0.0.
Paired p-value looks wrong
If paired = TRUE gives a surprising result, check the row order. By default the test pairs observations by row order. Add a subject identifier column and pass id; the manual says this works for a two-group, a pairwise and a ref.group comparison, uses only complete pairs, and is an error when combined with anova, kruskal.test or ref.group = ".all.".
Some panels or groups have no p-value
In grouped plots, if one or more subsets do not contain enough levels to identify the requested comparison, those subsets are skipped and valid subsets are still tested; this behaviour was added so one sparse subset no longer causes a fatal layer failure. If a facet is missing its label, count the observations per group in that facet.
Brackets or labels overlap
Set label.y to a vector of heights, one per comparison, and use step.increase to space brackets. When comparisons is used, brackets are drawn through ggsignif::geom_signif(), and tip.length is a fraction of the data range, so plots with different scales get different absolute tip lengths. For constant tip lengths across plots the manual recommends computing the tests with compare_means() and drawing them with stat_pvalue_manual(..., tip.length.ref = "axis").
Missing values are silently dropped
With na.rm = FALSE (the default) missing values are removed with a warning, as the manual states. Read the warning before you report the sample size under each box. ggboxplot() also has a show.n argument for displaying group sizes.
Reporting bugs
CRAN lists the issue tracker at github.com/kassambara/ggpubr/issues. Include the output of sessionInfo(), a minimal reproducible example using a built-in dataset, and the ggpubr and ggplot2 versions.
Free alternatives to ggpubr
ggpubr is free software (GPL), and so are the alternatives below. The right choice depends on whether you want plot wrappers, statistics with tidy output, or all-in-one plots with statistical detail. Descriptions are from each package’s CRAN page.
| Package | What CRAN says it does | Use it when |
|---|---|---|
| ggsignif | Provides a single layer, geom_signif(), that takes the groups for comparison and the test and adds a significance bracket to a ggplot |
You already have a ggplot and only need brackets. See ggsignif |
| rstatix | A pipe-friendly framework for basic statistical tests (t-test, Wilcoxon, ANOVA, Kruskal-Wallis, correlation) whose output is a tidy data frame | You want the test results as a table first and the plot second; ggpubr itself imports it |
| ggstatsplot | Creates graphics with details from statistical tests included in the plots, with parametric, nonparametric, robust and Bayesian versions of t-test/ANOVA | You want the full test statistics on the figure. See ggstatsplot |
| cowplot | Provides themes, functions to align and arrange plots into compound figures, and annotation functions for ggplot2 | You need multi-panel layout control; ggpubr’s ggarrange() is a wrapper around its plot_grid() |
The table is limited to what the CRAN descriptions and the ggpubr manual state; compare the current versions on each CRAN page before standardising a lab on one.
Sources
- CRAN: ggpubr, ‘ggplot2’ Based Publication Ready Plots, checked 2026-11-19
- CRAN: ggpubr reference manual (version 1.0.0), checked 2026-11-19
- ggpubr documentation site (Datanovia), checked 2026-11-19
- Anaconda.org: conda-forge r-ggpubr, checked 2026-11-19
- CRAN: ggsignif, checked 2026-11-19
- CRAN: rstatix, checked 2026-11-19
- CRAN: ggstatsplot, checked 2026-11-19
- CRAN: cowplot, checked 2026-11-19
Data: ggpubr p-value annotation functions: default test, adjustment and label settings
Compares the five ggpubr functions that put statistical results on a plot or return them as a table: compare_means, stat_compare_means, geom_pwc, stat_kruskal_test and stat_pvalue_manual. Values are the documented default arguments and notes in the ggpubr 1.0.0 reference manual on CRAN, read 2026-11-19.
Period covered: ggpubr 1.0.0, 2026-07-06.
| Function | Default test or source of p-values | Default p.adjust.method | Default p.format.style | Documented note |
|---|---|---|---|---|
| compare_means() | wilcox.test | holm | default | Returns a table; id argument pairs observations by subject for paired t.test or wilcox.test |
| stat_compare_means() | method set by the user (argument default NULL) | none argument; with comparisons the displayed p-values are not adjusted | default | paired = FALSE by default; label options p.signif, p.format, p.format.signif |
| geom_pwc() | wilcox_test | holm | default | Pairwise comparison layer; p.adjust.by default is group |
| stat_kruskal_test() | Kruskal-Wallis | holm | default | Default label is {method}, p = {p.format}; adjustment applies with multiple variables or groups |
| stat_pvalue_manual() | p-values supplied by the user in a data frame | none | default | Default p.digits is 3; takes y.position, group1 and group2 columns |
Sources
- CRAN: ggpubr reference manual (version 1.0.0) (accessed 2026-11-19)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







