Package Status Usage GitHub References
CRAN_Release_Badge Travis Build Status Daily downloads badge GitHub version Website
CRAN Checks AppVeyor Build Status Weekly downloads badge Github Pending PRs Rdoc
minimal R version lifecycle Monthly downloads badge Github Issues vignettes
GitHub code size in bytes Coverage Status Total downloads badge Github Stars DOI
Licence Codecov test coverage HitCount Last-changedate GitHub last commit
status Covrpage Summary saythanks Project Status contributions welcome
Gitter chat Dependency Status


ggstatsplot is an extension of ggplot2 package for creating graphics with details from statistical tests included in the plots themselves and targeted primarily at behavioral sciences community to provide a one-line code to produce information-rich plots. In a typical exploratory data analysis workflow, data visualization and statistical modeling are two different phases: visualization informs modeling, and modeling in its turn can suggest a different visualization method, and so on and so forth. The central idea of ggstatsplot is simple: combine these two phases into one in the form of graphics with statistical details, which makes data exploration simpler and faster.

Currently, it supports only the most common types of statistical tests: parametric, nonparametric, robust, and bayesian versions of t-test/anova, correlation analyses, contingency table analysis, and regression analyses.

It, therefore, produces a limited kinds of plots for the supported analyses:

  • violin plots (for comparisons between groups or conditions),
  • pie charts and bar charts (for categorical data),
  • scatterplots (for correlations between two variables),
  • correlation matrices (for correlations between multiple variables),
  • histograms and dot plots/charts (for hypothesis about distributions),
  • dot-and-whisker plots (for regression models).

In addition to these basic plots, ggstatsplot also provides grouped_ versions for most functions that makes it easy to repeat the same analysis for any grouping variable.

Future versions will include other types of statistical analyses and plots as well.

Statistical reporting

For all statistical tests reported in the plots, the default template abides by the APA gold standard for statistical reporting. For example, here are results from Yuen’s test for trimmed means (robust t-test):

Summary of supported statistical analyses

The table below summarizes all the different types of analyses currently supported in this package-

Functions Description Parametric Non-parametric Robust Bayes Factor
ggbetweenstats Between group/condition comparisons Yes Yes Yes Yes
gghistostats, ggdotplotstats Distribution of a numeric variable Yes Yes Yes Yes
ggcorrmat Correlation matrix Yes Yes Yes No
ggscatterstats Correlation between two variables Yes Yes Yes Yes
ggpiestats, ggbarstats Association between categorical variables Yes No No Yes
ggpiestats Proportion test No No No No
ggcoefstats Regression model coefficients Yes No Yes Yes

Effect sizes and confidence intervals available

ggstatsplot provides a wide range of effect sizes and their confidence intervals.

Test Parametric Non-parametric Robust Bayes
one-sample t-test Yes Yes Yes No
two-sample t-test (between) Yes Yes Yes No
two-sample t-test (within) Yes Yes Yes No
One-way ANOVA (between) Yes Yes Yes No
One-way ANOVA (within) Yes Yes No No
correlations Yes Yes Yes No
contingency table Yes NA NA No
goodness of fit Yes NA NA No
regression Yes Yes Yes No


To get the latest, stable CRAN release (0.0.10):

utils::install.packages(pkgs = "ggstatsplot")

Note: If you are on a linux machine, you will need to have OpenGL libraries installed (specifically, libx11, mesa and Mesa OpenGL Utility library - glu) for the dependency package rgl to work.

You can get the development version of the package from GitHub ( To see what new changes (and bug fixes) have been made to the package since the last release on CRAN, you can check the detailed log of changes here:

If you are in hurry and want to reduce the time of installation, prefer-

If time is not a constraint-

If you are not using the RStudio IDE and you get an error related to “pandoc” you will either need to remove the argument build_vignettes = TRUE (to avoid building the vignettes) or install pandoc. If you have the rmarkdown R package installed then you can check if you have pandoc by running the following in R:


If you want to cite this package in a scientific journal or in any other context, run the following code in your R console:

utils::citation(package = "ggstatsplot")

There is currently a publication in preparation corresponding to this package and the citation will be updated once it’s published.

Documentation and Examples

To see the detailed documentation for each function in the stable CRAN version of the package, see:

To see the documentation relevant for the development version of the package, see the dedicated website for ggstatplot, which is updated after every new commit:


In R, documentation for any function can be accessed with the standard help command (e.g., ?ggbetweenstats).

Another handy tool to see arguments to any of the functions is args. For example-

In case you want to look at the function body for any of the functions, just type the name of the function without the parentheses:

If you are not familiar either with what the namespace :: does or how to use pipe operator %>%, something this package and its documentation relies a lot on, you can check out these links-


ggstatsplot relies on non-standard evaluation (NSE), i.e., rather than looking at the values of arguments (x, y), it instead looks at their expressions. This means that you shouldn’t enter arguments with the $ operator and setting data = NULL: data = NULL, x = data$x, y = data$y. You must always specify the data argument for all functions. On the plus side, you can enter arguments either as a string (x = "x", y = "y") or as a bare expression (x = x, y = y) and it wouldn’t matter. To read more about NSE, see-

ggstatsplot is a very chatty package and will by default print helpful notes on assumptions about linear models, warnings, etc. If you don’t want your console to be cluttered with such messages, they can be turned off by setting argument messages = FALSE in the function call.

Here are examples of the main functions currently supported in ggstatsplot.

Note: If you are reading this on GitHub repository, the documentation below is for the development version of the package. So you may see some features available here that are not currently present in the stable version of this package on CRAN. For documentation relevant for the CRAN version, see:


This function creates either a violin plot, a box plot, or a mix of two for between-group or between-condition comparisons with results from statistical tests in the subtitle. The simplest function call looks like this-

Note that this function returns a ggplot2 object and thus any of the graphics layers can be further modified.

The type (of test) argument also accepts the following abbreviations: "p" (for parametric) or "np" (for nonparametric) or "r" (for robust) or "bf" (for Bayes Factor). Additionally, the type of plot to be displayed can also be modified ("box", "violin", or "boxviolin").

A number of other arguments can be specified to make this plot even more informative or change some of the default options.


# for reproducibility

# let's leave out one of the factor levels and see if instead of anova, a t-test will be run
iris2 <- dplyr::filter(.data = iris, Species != "setosa")

# let's change the levels of our factors, a common routine in data analysis
# pipeline, to see if this function respects the new factor levels
iris2$Species <-
  base::factor(x = iris2$Species,
               levels = c("virginica" , "versicolor"))

# plot
  data = iris2,                                    
  x = Species,
  y = Sepal.Length,
  notch = TRUE,                                   # show notched box plot
  mean.plotting = TRUE,                           # whether mean for each group is to be displayed = TRUE,                                 # whether to display confidence interval for means
  mean.label.size = 2.5,                          # size of the label for mean
  type = "p",                                     # which type of test is to be run
  bf.message = TRUE,                              # add a message with bayes factor favoring null
  k = 3,                                          # number of decimal places for statistical results
  outlier.tagging = TRUE,                         # whether outliers need to be tagged
  outlier.label = Sepal.Width,                    # variable to be used for the outlier tag
  outlier.label.color = "darkgreen",              # changing the color for the text label
  xlab = "Type of Species",                       # label for the x-axis variable
  ylab = "Attribute: Sepal Length",               # label for the y-axis variable
  title = "Dataset: Iris flower data set",        # title text for the plot
  ggtheme = ggthemes::theme_fivethirtyeight(),    # choosing a different theme
  ggstatsplot.layer = FALSE,                      # turn off ggstatsplot theme layer
  package = "wesanderson",                        # package from which color palette is to be taken
  palette = "Darjeeling1",                        # choosing a different color palette
  messages = FALSE

In case of a parametric t-test, setting bf.message = TRUE will also attach results from Bayesian Student’s t-test. That way, if the null hypothesis can’t be rejected with the NHST approach, the Bayesian approach can help index evidence in favor of the null hypothesis (i.e., BF01).

By default, Bayes Factor quantifies the support for the alternative hypothesis (H1) over the null hypothesis (H0) (i.e., BF10 is displayed). Natural logarithms are shown because BF values can be pretty large. This also makes it easy to compare evidence in favor alternative (BF10) versus null (BF01) hypotheses (since log(BF10) = - log(BF01)).

Additionally, there is also a grouped_ variant of this function that makes it easy to repeat the same operation across a single grouping variable:

Here is a summary of pairwise comparison tests supported in ggbetweenstats-

Type Design Equal variance? Test p-value adjustment?
Parametric between No Games-Howell test Yes
Parametric between Yes Student’s t-test Yes
Parametric within NA Student’s t-test Yes
Non-parametric between No Dwass-Steel-Crichtlow-Fligner test Yes
Non-parametric within No Durbin-Conover test Yes
Robust between No Yuen’s trimmed means test Yes
Robust within NA Yuen’s trimmed means test Yes
Bayes Factor between No No No
Bayes Factor between Yes No No
Bayes Factor within NA No No

For more, see the ggbetweenstats vignette:

This function is not appropriate for within-subjects designs.

Variant of this function ggwithinstats is currently under work. You can still use this function just to prepare the plot for exploratory data analysis, but the statistical details displayed in the subtitle will be incorrect. You can remove them by adding + ggplot2::labs(subtitle = NULL) to your function call.

As a temporary solution, you can use the helper function from ggstatsplot to display results from within-subjects version of the test in question. Here is an example-


This function creates a scatterplot with marginal histograms/boxplots/density/violin/densigram plots from ggExtra::ggMarginal and results from statistical tests in the subtitle:

Number of other arguments can be specified to modify this basic plot-

Additionally, there is also a grouped_ variant of this function that makes it easy to repeat the same operation across a single grouping variable:

For more, see the ggscatterstats vignette:


This function creates a pie chart for categorical or nominal variables with results from contingency table analysis (Pearson’s chi-squared test for between-subjects design and McNemar’s test for within-subjects design) included in the subtitle of the plot. If only one categorical variable is entered, results from one-sample proportion test will be displayed as a subtitle.

This function can also be used to study an interaction between two categorical variables. Additionally, this basic plot can further be modified with additional arguments and the function returns a ggplot2 object that can further be modified with ggplot2 syntax:

In case of within-subjects designs, setting paired = TRUE will produce results from McNemar test-

Additionally, there is also a grouped_ variant of this function that makes it easy to repeat the same operation across a single grouping variable:

For more, including information about the variant of this function grouped_ggpiestats, see the ggpiestats vignette:


In case you would like to see the distribution of one variable and check if it is significantly different from a specified value with a one sample test, this function will let you do that.

The type (of test) argument also accepts the following abbreviations: "p" (for parametric) or "np" (for nonparametric) or "r" (for robust) or "bf" (for Bayes Factor).

The aesthetic defaults can be easily modified-

As can be seen from the plot, bayes factor can be attached (bf.message = TRUE) to assess evidence in favor of the null hypothesis.

Additionally, there is also a grouped_ variant of this function that makes it easy to repeat the same operation across a single grouping variable:

For more, including information about the variant of this function grouped_gghistostats, see the gghistostats vignette:


ggcorrmat makes a correlalogram (a matrix of correlation coefficients) with minimal amount of code. Just sticking to the defaults itself produces publication-ready correlation matrices. But, for the sake of exploring the available options, let’s change some of the defaults. For example, multiple aesthetics-related arguments can be modified to change the appearance of the correlation matrix.

Note that if there are NAs present in the selected dataframe, the legend will display minimum, median, and maximum number of pairs used for correlation matrices.

Alternatively, you can use it just to get the correlation matrices and their corresponding p-values (in a tibble format). Also, note that if cor.vars are not specified, all numeric variables will be used.

# for reproducibility

# show four digits in a tibble
options(pillar.sigfig = 4)

# getting the correlation coefficient matrix 
  data = iris,               # all numeric variables from data will be used
  corr.method = "robust",
  output = "correlations",             # specifying the needed output ("r" or "corr" will also work)
  digits = 3                           # number of digits to be dispayed for correlation coefficient
#> # A tibble: 4 x 5
#>   variable     Sepal.Length Sepal.Width Petal.Length Petal.Width
#>   <chr>               <dbl>       <dbl>        <dbl>       <dbl>
#> 1 Sepal.Length        1          -0.143        0.878       0.837
#> 2 Sepal.Width        -0.143       1           -0.426      -0.373
#> 3 Petal.Length        0.878      -0.426        1           0.966
#> 4 Petal.Width         0.837      -0.373        0.966       1

# getting the p-value matrix
  data = ggplot2::msleep,
  cor.vars = sleep_total:bodywt,
  corr.method = "robust",
  output = "p.values",                  # only "p" or "p-values" will also work
  p.adjust.method = "holm"
#> # A tibble: 6 x 7
#>   variable  sleep_total sleep_rem sleep_cycle     awake   brainwt    bodywt
#>   <chr>           <dbl>     <dbl>       <dbl>     <dbl>     <dbl>     <dbl>
#> 1 sleep_to~   0.        5.291e-12   9.138e- 3 0.        3.170e- 5 2.568e- 6
#> 2 sleep_rem   4.070e-13 0.          1.978e- 2 5.291e-12 9.698e- 3 3.762e- 3
#> 3 sleep_cy~   2.285e- 3 1.978e- 2   0.        9.138e- 3 1.637e- 9 1.696e- 5
#> 4 awake       0.        4.070e-13   2.285e- 3 0.        3.170e- 5 2.568e- 6
#> 5 brainwt     4.528e- 6 4.849e- 3   1.488e-10 4.528e- 6 0.        4.509e-17
#> 6 bodywt      2.568e- 7 7.524e- 4   2.120e- 6 2.568e- 7 3.221e-18 0.

# getting the confidence intervals for correlations
  data = ggplot2::msleep,
  cor.vars = sleep_total:bodywt,
  corr.method = "kendall",
  output = "ci",                  
  p.adjust.method = "holm"
#> Note: In the correlation matrix,
#> the upper triangle: p-values adjusted for multiple comparisons
#> the lower triangle: unadjusted p-values.
#> # A tibble: 15 x 7
#>    pair                 r     lower     upper         p lower.adj upper.adj
#>    <chr>            <dbl>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>
#>  1 sleep_total-s~  0.5922  4.000e-1  7.345e-1 4.981e- 7   0.3027    0.7817 
#>  2 sleep_total-s~ -0.3481 -6.214e-1  6.818e-4 5.090e- 2  -0.6789    0.1002 
#>  3 sleep_total-a~ -1      -1.000e+0 -1.000e+0 0.         -1        -1      
#>  4 sleep_total-b~ -0.4293 -6.220e-1 -1.875e-1 9.621e- 4  -0.6858   -0.07796
#>  5 sleep_total-b~ -0.3851 -5.547e-1 -1.847e-1 3.247e- 4  -0.6050   -0.1106 
#>  6 sleep_rem-sle~ -0.2066 -5.180e-1  1.531e-1 2.566e- 1  -0.5180    0.1531 
#>  7 sleep_rem-awa~ -0.5922 -7.345e-1 -4.000e-1 4.981e- 7  -0.7832   -0.2990 
#>  8 sleep_rem-bra~ -0.2636 -5.096e-1  2.217e-2 7.022e- 2  -0.5400    0.06404
#>  9 sleep_rem-bod~ -0.3163 -5.262e-1 -7.004e-2 1.302e- 2  -0.5662   -0.01317
#> 10 sleep_cycle-a~  0.3481 -6.818e-4  6.214e-1 5.090e- 2  -0.1145    0.6867 
#> 11 sleep_cycle-b~  0.7125  4.739e-1  8.536e-1 1.001e- 5   0.3239    0.8954 
#> 12 sleep_cycle-b~  0.6545  3.962e-1  8.168e-1 4.834e- 5   0.2459    0.8656 
#> 13 awake-brainwt   0.4293  1.875e-1  6.220e-1 9.621e- 4   0.08322   0.6829 
#> 14 awake-bodywt    0.3851  1.847e-1  5.547e-1 3.247e- 4   0.1049    0.6087 
#> 15 brainwt-bodywt  0.8378  7.373e-1  9.020e-1 8.181e-16   0.6716    0.9238

# getting the sample sizes for all pairs
  data = ggplot2::msleep,
  cor.vars = sleep_total:bodywt,
  corr.method = "robust",
  output = "n"                           # note that n is different due to NAs
#> # A tibble: 6 x 7
#>   variable    sleep_total sleep_rem sleep_cycle awake brainwt bodywt
#>   <chr>             <dbl>     <dbl>       <dbl> <dbl>   <dbl>  <dbl>
#> 1 sleep_total          83        61          32    83      56     83
#> 2 sleep_rem            61        61          32    61      48     61
#> 3 sleep_cycle          32        32          32    32      30     32
#> 4 awake                83        61          32    83      56     83
#> 5 brainwt              56        48          30    56      56     56
#> 6 bodywt               83        61          32    83      56     83

Additionally, there is also a grouped_ variant of this function that makes it easy to repeat the same operation across a single grouping variable:

For examples and more information, see the ggcorrmat vignette:


ggcoefstats creates a lot with the regression coefficients’ point estimates as dots with confidence interval whiskers.

The basic plot can be further modified to one’s liking with additional arguments (also, let’s use a robust linear model instead of a simple linear model now):

Most of the regression models that are supported in the broom and broom.mixed packages with tidy and glance methods are also supported by ggcoefstats. For example-

aareg, anova, aov, aovlist, Arima, biglm, brmsfit, btergm, cch, clm, clmm, confusionMatrix, coxph, ergm, felm, fitdistr, glmerMod, glmmTMB, gls, gam, Gam, gamlss, garch, glm, glmmadmb, glmmTMB, glmrob, gmm, ivreg, lm, lm.beta, lmerMod, lmodel2, lmrob, mcmc, MCMCglmm, mediate, mjoint, mle2, multinom, nlmerMod, nlrq, nls, orcutt, plm, polr, ridgelm, rjags, rlm, rlmerMod, rq, speedglm, speedlm, stanreg, survreg, svyglm, svyolr, svyglm, etc.

For an exhaustive list of all regression models supported by ggcoefstats and what to do in case the regression model you are interested in is not supported, see the associated vignette-


The full power of ggstatsplot can be leveraged with a functional programming package like purrr that replaces for loops with code that is both more succinct and easier to read and, therefore, purrr should be preferrred 😻. (Another old school option to do this effectively is using the plyr package.)

In such cases, ggstatsplot contains a helper function combine_plots to combine multiple plots, which can be useful for combining a list of plots produced with purrr. This is a wrapper around cowplot::plot_grid and lets you combine multiple plots and add a combination of title, caption, and annotation texts with suitable defaults.

For examples (both with plyr and purrr), see the associated vignette-


All plots from ggstatsplot have a default theme: theme_ggstatsplot. You can change this theme by using the argument ggtheme for all functions.

It is important to note that irrespective of which ggplot theme you choose, ggstatsplot in the backdrop adds a new layer with its idiosyncratic theme settings, chosen to make the graphs more readable or aesthetically pleasing. Let’s see an example with gghistostats and see how a certain theme from hrbrthemes package looks with and without the ggstatsplot layer.

For more on how to modify it, see the associated vignette-

Using ggstatsplot helpers to display text results

Sometimes you may not like the default plot produced by ggstatsplot. In such cases, you can use other custom plots (from ggplot2 or other plotting packages) and still use ggstatsplot (subtitle) helper functions to display results from relevant statistical test. For example, in the following chunk, we will use pirateplot from yarrr package and use ggstatsplot helper function to display the results.

Code coverage

As the code stands right now, here is the code coverage for all primary functions involved:


I’m happy to receive bug reports, suggestions, questions, and (most of all) contributions to fix problems and add features. I personally prefer using the Github issues system over trying to reach out to me in other ways (personal e-mail, Twitter, etc.). Pull requests for contributions are encouraged.

Here are some simple ways in which you can contribute:

  • Read and correct any inconsistencies in the documentation

  • Raise issues about bugs or wanted features

  • Review code

  • Add new functionality (in the form of new plotting functions or helpers for preparing subtitles)

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Session Information

For details about the session information in which this README file was rendered, see-