'ggplot2' Based Plots with Statistical Details

Extension of 'ggplot2', 'ggstatsplot' creates graphics with details from statistical tests included in the plots themselves. It is targeted primarily at behavioral sciences community to provide a one-line code to generate information-rich plots for statistical analysis. of continuous (violin plots, scatterplots, histograms) or categorical (pie charts) data. 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.

CRAN_Release_Badge CRANChecks packageversion CoverageStatus Daily downloadsbadge Weekly downloadsbadge Monthly downloadsbadge Total downloadsbadge Travis BuildStatus AppVeyor BuildStatus Licence Last-changedate lifecycle minimal Rversion Project Status: Active - The project has reached a stable, usablestate and is being activelydeveloped. PendingPull-Requests GithubIssues


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 modelling are two different phases: visualization informs modelling, and modelling 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, and robust versions of t-test, anova, and 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 (for categorical data),
  • scatterplots (for correlations between two variables),
  • correlation matrices (for correlations between multiple variables),
  • histograms (for hypothesis about distributions), and
  • 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.


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

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

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: https://indrajeetpatil.github.io/ggstatsplot/news/index.html

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

# needed package to download from GitHub repo
utils::install.packages(pkgs = "devtools")   
# downloading the package from GitHub
  repo = "IndrajeetPatil/ggstatsplot", # package path on GitHub
  dependencies = FALSE,                # assumes that you already have all packages installed needed for this package to work
  quick = TRUE                         # skips docs, demos, and vignettes

If time is not a constraint-

  repo = "IndrajeetPatil/ggstatsplot", # package path on GitHub
  dependencies = TRUE,                 # installs packages which ggstatsplot depends on
  upgrade_dependencies = TRUE          # updates any out of date dependencies

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:

#> [1] TRUE


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 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: https://indrajeetpatil.github.io/ggstatsplot/.


In R, documentation for any function can be accessed with the standard help command-

# primary functions
# grouped variants of primary functions
# helper functions

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

args(name = ggstatsplot::ggscatterstats)
#> function (data, x, y, label.var = NULL, label.expression = NULL, 
#>     xlab = NULL, ylab = NULL, method = "lm", method.args = list(), 
#>     formula = y ~ x, point.color = "black", point.size = 3, point.alpha = 0.4, 
#>     point.width.jitter = NULL, point.height.jitter = NULL, line.size = 1.5, 
#>     line.color = "blue", marginal = TRUE, marginal.type = "histogram", 
#>     marginal.size = 5, margins = c("both", "x", "y"), package = "wesanderson", 
#>     palette = "Royal1", direction = 1, xfill = "#009E73", yfill = "#D55E00", 
#>     xalpha = 1, yalpha = 1, xsize = 0.7, ysize = 0.7, centrality.para = NULL, 
#>     type = "pearson", results.subtitle = TRUE, title = NULL, 
#>     subtitle = NULL, caption = NULL, nboot = 100, beta = 0.1, 
#>     k = 3, axes.range.restrict = FALSE, ggtheme = ggplot2::theme_bw(), 
#>     ggstatsplot.layer = TRUE, messages = TRUE) 

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:

#> function(ggtheme = ggplot2::theme_bw(),
#>                               ggstatsplot.layer = TRUE) {
#>   if (isTRUE(ggstatsplot.layer)) {
#>     ggtheme +
#>       ggplot2::theme(
#>         axis.title.x = ggplot2::element_text(size = 10, face = "bold"),
#>         strip.text.x = ggplot2::element_text(size = 10, face = "bold"),
#>         strip.text.y = ggplot2::element_text(size = 10, face = "bold"),
#>         strip.text = ggplot2::element_text(size = 10, face = "bold"),
#>         axis.title.y = ggplot2::element_text(size = 10, face = "bold"),
#>         axis.text.x = ggplot2::element_text(size = 10, face = "bold"),
#>         axis.text.y = ggplot2::element_text(size = 10, face = "bold"),
#>         axis.line = ggplot2::element_line(),
#>         legend.text = ggplot2::element_text(size = 10),
#>         legend.title = ggplot2::element_text(size = 10, face = "bold"),
#>         legend.title.align = 0.5,
#>         legend.text.align = 0.5,
#>         legend.key.height = grid::unit(x = 1, units = "line"),
#>         legend.key.width = grid::unit(x = 1, units = "line"),
#>         plot.margin = grid::unit(x = c(1, 1, 1, 1), units = "lines"),
#>         panel.border = ggplot2::element_rect(
#>           color = "black",
#>           fill = NA,
#>           size = 1
#>         ),
#>         plot.title = ggplot2::element_text(
#>           color = "black",
#>           size = 13,
#>           face = "bold",
#>           hjust = 0.5
#>         ),
#>         plot.subtitle = ggplot2::element_text(
#>           color = "black",
#>           size = 10,
#>           face = "plain",
#>           hjust = 0.5
#>         )
#>       )
#>   } else {
#>     ggtheme
#>   }
#> }
#> <bytecode: 0x000000002915e4f0>
#> <environment: namespace:ggstatsplot>

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, which means you shouldn’t enter arguments in the following manner: data = NULL, x = data$x, y = data$y. You must always specify the data argument for all functions.

Additionally, ggstatsplot is a very chatty package and will by default output information about references for tests, notes on assumptions about linear models, and warnings. 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: 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 the vignettes on the site: https://cran.r-project.org/web/packages/ggstatsplot/vignettes/


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-

# loading needed libraries
# for reproducibility
# plot
  data = datasets::iris, 
  x = Species, 
  y = Sepal.Length,
  messages = FALSE
) +                                               # further modification outside of ggstatsplot
  ggplot2::coord_cartesian(ylim = c(3, 8)) + 
  ggplot2::scale_y_continuous(breaks = seq(3, 8, by = 1)) 

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 = datasets::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 
  mean.ci = 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 in favor of the null
  k = 2,                                          # 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:

# for reproducibility
# plot
  data = ggstatsplot::movies_long, 
  x = mpaa, 
  y = length,
  grouping.var = genre,            # grouping variable
  title.prefix = "Movie genre",
  palette = "default_jama",
  package = "ggsci",
  messages = FALSE,
  nrow = 2,
  ncol = 2,
  title.text = "Differences in movie length by mpaa ratings for different genres"

For more, see the ggbetweenstats vignette: https://indrajeetpatil.github.io/ggstatsplot/articles/ggbetweenstats.html

** 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-

# for reproducibility
# creating a smaller dataframe
intent_short <- ggstatsplot::intent_morality %>%
  dplyr::filter(.data = ., condition %in% c("accidental", "attempted")) 
# getting text results using with a helper function
results_subtitle <- ggstatsplot::subtitle_ggbetween_t_parametric(
  data = intent_short,
  x = condition,
  y = rating,
  paired = TRUE
# displaying the subtitle on the plot
  data = intent_short,
  x = condition,
  y = rating,
  messages = FALSE
) +
  ggplot2::labs(subtitle = results_subtitle)


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

  data = ggplot2::msleep, 
  x = sleep_rem, 
  y = awake,
  xlab = "REM sleep (in hours)",
  ylab = "Amount of time spent awake (in hours)",
  title = "Understanding mammalian sleep",
  messages = FALSE

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

# for reproducibility
# plot
  data = dplyr::filter(.data = ggstatsplot::movies_long, genre == "Action"),
  x = budget,
  y = rating,
  type = "robust",                                # type of test that needs to be run
  xlab = "Movie budget (in million/ US$)",        # label for x axis
  ylab = "IMDB rating",                           # label for y axis 
  label.var = "title",                            # variable for labeling data points
  label.expression = "rating < 5 & budget > 150", # expression that decides which points to label
  line.color = "yellow",                          # changing regression line color line
  title = "Movie budget and IMDB rating (action)",# title text for the plot
  caption = expression(                           # caption text for the plot
    paste(italic("Note"), ": IMDB stands for Internet Movie DataBase")
  ggtheme = hrbrthemes::theme_ipsum_ps(),         # choosing a different theme
  ggstatsplot.layer = FALSE,                      # turn off ggstatsplot theme layer
  marginal.type = "density",                      # type of marginal distribution to be displayed
  xfill = "#0072B2",                              # color fill for x-axis marginal distribution 
  yfill = "#009E73",                              # color fill for y-axis marginal distribution
  xalpha = 0.6,                                   # transparency for x-axis marginal distribution
  yalpha = 0.6,                                   # transparency for y-axis marginal distribution
  centrality.para = "median",                     # which type of central tendency lines are to be displayed  
  point.width.jitter = 0.2,                       # amount of horizontal jitter for data points
  point.height.jitter = 0.4,                      # amount of vertical jitter for data points
  messages = FALSE                                # turn off messages and notes

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 reproducibility
# plot
  data = ggstatsplot::movies_long, 
  x = rating, 
  y = length,
  xfill = "#E69F00", 
  yfill = "#8b3058",
  xlab = "IMDB rating",
  grouping.var = genre,            # grouping variable
  title.prefix = "Movie genre",
  ggtheme = ggplot2::theme_grey(),
  messages = FALSE,
  nrow = 2,
  ncol = 2,
  title.text = "Relationship between movie length by IMDB ratings for different genres"

For more, see the ggscatterstats vignette: https://indrajeetpatil.github.io/ggstatsplot/articles/ggscatterstats.html


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.

# for reproducibility
# plot
  data = ggplot2::msleep,
  main = vore,
  title = "Composition of vore types among mammals",
  messages = FALSE

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:

# for reproducibility
# plot
  data = datasets::mtcars,
  main = am,
  condition = cyl,
  title = "Dataset: Motor Trend Car Road Tests",      # title for the plot
  stat.title = "interaction: ",                       # title for the results from Pearson's chi-squared test
  legend.title = "Transmission",                      # title for the legend
  factor.levels = c("1 = manual", "0 = automatic"),   # renaming the factor level names for 'main' variable 
  facet.wrap.name = "No. of cylinders",               # name for the facetting variable
  facet.proptest = FALSE,                             # turning of facetted proportion test results
  package = "ggsci",                                  # package from which color palette is to be taken
  palette = "default_jama",                           # choosing a different color palette 
  caption = expression(                               # text for the caption
    paste(italic("Note"), ": this is a demo")
  messages = FALSE                                    # turn off messages and notes

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

# for reproducibility
# data
survey.data <- data.frame(
  `1st survey` = c('Approve', 'Approve', 'Disapprove', 'Disapprove'),
  `2nd survey` = c('Approve', 'Disapprove', 'Approve', 'Disapprove'),
  `Counts` = c(794, 150, 86, 570),
  check.names = FALSE
# plot
  data = survey.data,
  main = `1st survey`,
  condition = `2nd survey`,
  counts = Counts,
  paired = TRUE,                      # within-subjects design
  stat.title = "McNemar Test: ",
  package = "wesanderson",
  palette = "Royal1"

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 reproducibility
# plot
  data = ggstatsplot::movies_long, 
  main = mpaa,
  grouping.var = genre,            # grouping variable
  title.prefix = "Movie genre",
  palette = "BrightPastel",
  package = "quickpalette",
  messages = FALSE,
  nrow = 2,
  ncol = 2,
  title.text = "Composition of MPAA ratings for different genres"

For more, including information about the variant of this function grouped_ggpiestats, see the ggpiestats vignette: https://indrajeetpatil.github.io/ggstatsplot/articles/ggpiestats.html


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).

  data = datasets::ToothGrowth,             # dataframe from which variable is to be taken
  x = len,                                  # numeric variable whose distribution is of interest
  title = "Distribution of Sepal.Length",   # title for the plot
  fill.gradient = TRUE,                     # use color gradient
  test.value = 10,                          # the comparison value for t-test
  test.value.line = TRUE,                   # display a vertical line at test value
  type = "bf",                              # bayes factor for one sample t-test
  bf.prior = 0.8,                           # prior width for calculating the bayes factor
  messages = FALSE                          # turn off the messages

The aesthetic defaults can be easily modified-

Note: To use bar.measure = "mix" option, you will need to get the development version of ggplot2 from GitHub.

# getting development version of ggplot2
# devtools::install_github(repo = "tidyverse/ggplot2", dependencies = FALSE)
# plot
  data = datasets::iris,                         # dataframe from which variable is to be taken
  x = Sepal.Length,                              # numeric variable whose distribution is of interest
  title = "Distribution of Iris sepal length",   # title for the plot
  type = "parametric",                           # one sample t-test
  bar.measure = "mix",                           # what does the bar length denote
  test.value = 5,                                # default value is 0
  test.value.line = TRUE,                        # display a vertical line at test value
  test.value.color = "#0072B2",                  # color for the line for test value
  centrality.para = "mean",                      # which measure of central tendency is to be plotted
  centrality.color = "darkred",                  # decides color of vertical line representing central tendency
  binwidth = 0.10,                               # binwidth value (experiment until you find the best one)
  bf.message = TRUE,                             # display bayes factor for null over alternative
  bf.prior = 0.8,                                # prior width for computing bayes factor
  messages = FALSE,                              # turn off the messages
  ggtheme = hrbrthemes::theme_ipsum_tw(),        # choosing a different theme
  ggstatsplot.layer = FALSE                      # turn off ggstatsplot theme layer

As can be seen from the plot, bayes factor can be attached (using 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 reproducibility
# plot
  data = ggstatsplot::movies_long, 
  x = budget,
  xlab = "Movies budget (in million US$)",
  grouping.var = genre,            # grouping variable
  title.prefix = "Movie genre",
  ggtheme = ggthemes::theme_tufte(),
  messages = FALSE,
  nrow = 2,
  ncol = 2,
  title.text = "Movies budgets for different genres"

For more, including information about the variant of this function grouped_gghistostats, see the gghistostats vignette: https://indrajeetpatil.github.io/ggstatsplot/articles/gghistostats.html


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.

# as a default this function outputs a correlalogram plot
  data = ggplot2::msleep,
  corr.method = "robust",                    # correlation method
  sig.level = 0.001,                         # threshold of significance
  p.adjust.method = "holm",                  # p-value adjustment method for multiple comparisons
  cor.vars = c(sleep_rem, awake:bodywt),     # a range of variables can be selected  
  cor.vars.names = c("REM sleep",            # variable names
                     "time awake", 
                     "brain weight", 
                     "body weight"), 
  matrix.type = "upper",                     # type of visualization matrix
  colors = c("#B2182B", "white", "#4D4D4D"), 
  title = "Correlalogram for mammals sleep dataset",
  subtitle = "sleep units: hours; weight units: kilograms"
#> Note: In the correlation matrix, the upper triangle is based on p-values adjusted for multiple comparisons,
#> while the lower triangle is based on unadjusted p-values.

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

Multiple aesthetics-related arguments can be modified to change the appearance of the correlation matrix.

Alternatively, you can use it just to get the correlation matrices and their corresponding p-values (in a tibble format).

# show four digits in a tibble
options(pillar.sigfig = 4)
# getting the correlation coefficient matrix
  data = datasets::iris,
  cor.vars = Sepal.Length:Petal.Width,
  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"
#> Note: In the correlation matrix, the upper triangle denotes p-values adjusted for multiple comparisons,
#> while the lower triangle denotes unadjusted p-values.
#> # A tibble: 6 x 7
#>   variable sleep_total sleep_rem sleep_cycle     awake   brainwt    bodywt
#>   <chr>          <dbl>     <dbl>       <dbl>     <dbl>     <dbl>     <dbl>
#> 1 sleep_t~   0.        5.291e-12   9.138e- 3 0.        3.170e- 5 2.568e- 6
#> 2 sleep_r~   4.070e-13 0.          1.978e- 2 5.291e-12 9.698e- 3 3.762e- 3
#> 3 sleep_c~   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 sample sizes for all pairs
  data = ggplot2::msleep,
  cor.vars = sleep_total:bodywt,
  corr.method = "robust",
  output = "n"
#> # 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 reproducibility
# plot
# let's use only 50% of the data to speed up the process
  data = dplyr::sample_frac(ggstatsplot::movies_long, size = 0.5),
  cor.vars = length:votes,
  corr.method = "np",
  colors = c("#cbac43", "white", "#550000"),
  grouping.var = genre,                      # grouping variable
  title.prefix = "Movie genre",
  messages = FALSE,
  nrow = 2,
  ncol = 2

For examples and more information, see the ggcorrmat vignette: https://indrajeetpatil.github.io/ggstatsplot/articles/ggcorrmat.html


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

ggstatsplot::ggcoefstats(x = stats::lm(formula = mpg ~ am * cyl,
                                       data = datasets::mtcars)) 

The basic 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):

  x = MASS::rlm(formula = mpg ~ am * cyl,
                data = datasets::mtcars),
  point.color = "red",                
  point.shape = 15,
  vline.color = "#CC79A7",
  vline.linetype = "dotdash",
  stats.label.size = 3.5,
  stats.label.color = c("#0072B2", "#D55E00", "darkgreen"),
  title = "Car performance predicted by transmission & cylinder count",
  subtitle = "Source: 1974 Motor Trend US magazine",
  ggtheme = ggthemes::theme_stata(),
  ggstatsplot.layer = FALSE
) +                                    
  # further modification with the ggplot2 commands
  # note the order in which the labels are entered
  ggplot2::scale_y_discrete(labels = c("transmission", "cylinders", "interaction")) +
  ggplot2::labs(x = "regression coefficient",
                y = NULL)

All the regression model classes that are supported in the broom package with tidy and glance methods (https://broom.tidyverse.org/articles/available-methods.html) are also supported by ggcoefstats. Additionally, we can make a number of aesthetic modifications by changing the defaults for theme and palette.

Let’s see a couple more examples:

# for reproducibility
# creating dataframe needed for one of the analyses below
d <- as.data.frame(Titanic)
# combining plots together
  # quantile regression
  x = quantreg::rq(
    formula = stack.loss ~ stack.x,
    data = stackloss,
    method = "br"
  se.type = "iid",
  title = "quantile regression"
  # linear mmodel
    x = lme4::lmer(
      formula = Reaction ~ Days + (Days | Subject),
      data = lme4::sleepstudy
    point.color = "red",
    stats.label.color = "black",
    ggtheme = hrbrthemes::theme_ipsum_ps(),
    ggstatsplot.layer = FALSE,
    exclude.intercept = FALSE,
    title = "linear mixed-effects model"
  labels = c("(a)", "(b)"),
  nrow = 2,
  ncol = 1

This is by no means an exhaustive list of models supported by ggcoefstats. For a more thorough discussion about all regression models supported, see the associated vignette- https://indrajeetpatil.github.io/ggstatsplot/articles/ggcoefstats.html


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- https://indrajeetpatil.github.io/ggstatsplot/articles/combine_plots.html


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.

# to use hrbrthemes themes, first make sure you have all the necessary fonts
# extrafont::ttf_import()
# extrafont::font_import()
# try this yourself
  # with the ggstatsplot layer
    data = datasets::iris,
    x = Sepal.Width,
    messages = FALSE,
    title = "Distribution of Sepal Width",
    test.value = 5,
    ggtheme = hrbrthemes::theme_ipsum(),
    ggstatsplot.layer = TRUE
  # without the ggstatsplot layer
    data = datasets::iris,
    x = Sepal.Width,
    messages = FALSE,
    title = "Distribution of Sepal Width",
    test.value = 5,
    ggtheme = hrbrthemes::theme_ipsum_ps(),
    ggstatsplot.layer = FALSE
  nrow = 1,
  labels = c("(a)", "(b)"),
  title.text = "Behavior of ggstatsplot theme layer with chosen ggtheme"

For more on how to modify it, see the associated vignette- https://indrajeetpatil.github.io/ggstatsplot/articles/theme_ggstatsplot.html

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.

# for reproducibility
# loading the needed libraries
# using `ggstatsplot` to prepare text with statistical results
stats_results <-
    data = ChickWeight,
    x = Time,
    y = weight,
    messages = FALSE
# using `yarrr` to create plot
  formula = weight ~ Time,
  data = ChickWeight,
  theme = 1,
  main = stats_results

Code coverage

As the code stands right now, here is the code coverage for all primary functions involved: https://codecov.io/gh/IndrajeetPatil/ggstatsplot/tree/master/R


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.

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.


ggstatsplot 0.0.6


  • The package now exports all functions used to create text expressions with results. This makes it easy for people to use these results in their own plots at any location they want (and not just in subtitle, the current default for ggstatsplot).
  • ggcorrmat gains p.adjust.method argument which allows p-values for correlations to be corrected for multiple comparisons.
  • ggscatterstats gains label.var and label.expression arguments to attach labels to points.
  • gghistostats now defaults to not showing (redundant) color gradient (fill.gradient = FALSE) and shows both "count" and "proportion" data. It also gains a new argument bar.fill that can be used to fill bars with a uniform color.
  • ggbetweenstats, ggcoefstats, ggcorrmat, ggscatterstats, and ggpiestats now support all palettes contained in the paletteer package. This helps avoid situations where people had large number of groups (> 12) and there were not enough colors in any of the RColorBrewer palettes.
  • ggbetweenstats gains bf.message argument to display bayes factors in favor of the null (currently works only for parametric t-test).
  • gghistostats function no longer has line.labeller.y argument; this position is automatically determined now.


  • legend.title.margin function has been depcrecated since ggplot2 3.0.0 has improved on the margin issues from previous versions. All functions that wrapped around this function now lose the relevant arguments (legend.title.margin, t.margin, b.margin).
  • The argument ggstatsplot.theme has been changed to ggstatsplot.layer for ggcorrmat function to be consistent across functions.
  • For consistency, conf.level and conf.type arguments for ggbetweenstats have been deprecated. No other function in the package allowed changing confidence interval or their type for effect size estimation. These arguments were relevant only for robust tests anyway.
  • ggocorrmat argument type has been changed to matrix.type because for all other functions type argument specifies the type of the test, while for this function it specified the display of the virsualization matrix. This will make the syntax more consistent across functions.
  • ggscatterstats gains new arguments to specify aesthetics for geom point (point.color, point.size, point.alpha). To be consistent with this naming schema, the width.jitter and height.jitter arguments have been renamed to point.width.jitter and point.height.jitter, resp.


  • gghistostats: To be compatible with JASP, natural logarithm of Bayes Factors is displayed, and not base 10 logarithm.
  • ggscatterstats gains method and formula arguments to modify smoothing functions.
  • ggcorrmat can now show robust correlation coefficients in the matrix plot.
  • For gghistostats, binwidth value, if not specified, is computed with (max-min)/sqrt(n). This is basically to get rid of the warnings ggplot2 produces. Thanks to Chuck Powell's PR (#43).
  • ggcoefstats gains a new argument partial and can display eta-squared and omega-squared effect sizes for anovas, in addition to the prior partial variants of these effect sizes.
  • ggpiestats gains perc.k argument to show desired number of decimal places in percentage labels.


  • grouped_ggpiestats wasn't working when only main variable was provided with counts data. Fixed that.

ggstatsplot 0.0.5


  • For the sake of consistency, theme_mprl is now called theme_ggstatsplot. The theme_mprl function will still be around and will not be deprecated, so feel free to use either or both of them since they are identical.
  • ggcoefstats no longer has arguments effects and ran_params because only fixed effects are shown for mixed-effects models.
  • ggpiestats can now handle within-subjects designs (McNemar test results will be displayed).


  • ggbetweenstats was producing wrong axes labels when sample.size.label was set to TRUE and user had reordered factor levels before using this function. The new version fixes this.
  • ggcoefstats wasn't producing partial omega-squared for aovlist objects. Fixed that with new version of sjstats.


  • Removed the trailing comma from the robust correlation analyses.
  • gghistostats has a new argument to remove color fill gradient.
  • ggbetweenstats takes new argument mean.ci to show confidence intervals for the mean values.
  • For lmer models, p-values are now computed using sjstats::p_value. This removes lmerTest package from dependencies.
  • sjstats no longer suggests apaTables package to compute confidence intervals for partial eta- and omega-squared. Therefore, apaTables and MBESS are removed from dependencies.
  • ggscatterstats supports densigram with the development version of ggExtra. It additionally gains few extra arguments to change aesthetics of marginals (alpha, size, etc.).

ggstatsplot 0.0.4


  • New function: ggcoefstats for displaying model coefficients.
  • All functions now have ggtheme argument that can be used to change the default theme, which has now been changed from theme_grey() to theme_bw().
  • The robust correlation is no longer MASS::rlm, but percentage bend correlation, as implemented in WRS2::pbcor. This was done to be consistent across different functions. ggcorrmat also uses percentage bend correlation as the robust correlation measure. This also means that ggstatsplot no longer imports MASS and sfsmisc.
  • The data argument is no longer NULL for all functions, except gghistostats. In other words, the user must provide a dataframe from which variables or formulas should be selected.
  • All subtitles containing results now also show sample size information (n). To adjust for the inflated length of the subtitle, the default subtitle text size has been changed from 12 to 11.


  • Switched back to Shapiro-Wilk test of normality to remove nortest from imports.
  • ggpiestats can now handle dataframes with
  • ggbetweenstats and ggpiestats now display sample sizes for each level of the groping factor by default. This behavior can be turned off by setting sample.size.label to FALSE.
  • Three new datasets added: Titanic_full, movies_wide, movies_long.
  • Added confidence interval for effect size for robust ANOVA.
  • The 95% CI for Cramer'V computed using boot::boot. Therefore, the package no longer imports DescTools.
  • To be consistent across correlations covered, all correlations now show estimates for correlation coefficients, confidence intervals for the estimate, and p-values. Therefore, t-values and regression coefficients are no longer displayed for Pearson's r.
  • The legend.title.margin arguments for gghistostats and ggcorrmat now default to FALSE, since ggplot2 3.0.0 has better legend title margins.
  • ggpiestats now sorts the summary dataframes not by percentages but by the levels of main variable. This was done to have the same legends across different levels of a grouping variable in grouped_ggpiestats.
  • To remove cluttered display of results in the subtitle, ggpiestats no longer shows titles for the tests run (these were "Proportion test" and "Chi-Square test"). From the pie charts, it should be obvious to the user or reader what test was run.
  • gghistostats also allows running robust version of one-sample test now (One-sample percentile bootstrap).

ggstatsplot 0.0.3


  • The ggbetweenstats function can now show notched box plots. Two new arguments notch and notchwidth control its behavior. The defaults are still standard box plots.
  • Removed warnings that were appearing when outlier.label argument was of character type.
  • The default color palette used for all plots is colorblind friendly.
  • gghistostats supports proportion and density as a value measure for bar heights to show proportions and density. New argument bar.measure controls this behavior.
  • grouped_ variants of functions ggcorrmat, ggscatterstats, ggbetweenstats, and ggpiestats introduced to create multiple plots for different levels of a grouping variable.


  • To be internally consistent, all functions in ggstatsplot use the spelling color, rather than colour in some functions, while color in others.
  • Removed the redundant argument binwidth.adjust from gghistostats function. This argument was relevant for the first avatar of this fucntion, but is no longer playing any role.
  • To be internally consistent, the argument lab_col and lab_size in ggcorrmat have been changed to lab.col and lab.size, respectively.


  • Added a new argument to ggstatsplot.theme function to control if ggstatsplot::theme_mprl is to be overlaid on top of the selected ggtheme (ggplot2 theme, i.e.).
  • Two new arguments added to gghistostats to allow user to change colorbar gradient. Defaults are colorblind friendly.
  • Both gghistostats and ggcorrmat have a new argument legend.title.margin to control margin adjustment between the title and the colorbar.
  • The vertical lines denoting test values and centrality parameters can be tagged with text labels with a new argument line.labeller in gghistostats function.


  • The centrality.para argument for ggscatterstats was not working properly. Choosing "median" didn't show median, but the mean. This is fixed now.

ggstatsplot 0.0.2


  • Bayesian test added to gghistostats and two new arguments to also display a vertical line for test.value argument.
  • Vignette added for gghistostats.
  • Added new function grouped_gghistostats to facilitate applying gghistostats for multiple levels of a grouping factor.
  • ggbetweenstats has a new argument outlier.coef to adjust threshold used to detect outliers. Removed bug from the same function when outlier.label argument is of factor/character type.


  • Functions signif_column and grouped_proptest are now deprecated. They were exported in the first release by mistake.
  • Function gghistostats no longer displays both density and count since the density information was redundant. The density.plot argument has also been deprecated.
  • ggscatterstats argument intercept has now been changed to centrality.para. This was due to possible confusion about interpreation of these lines; they show central tendency measures and not intercept for the linear model. Thus the change.
  • The default for effsize.type = "biased" effect size for ggbetweenstats in case of ANOVA is partial omega-squared, and not omega-squared. Additionally, both partial eta- and omega-squared are not computed using bootstrapping with (default) 100 bootstrap samples.


  • More examples added to the README document.
  • 95% confidence intervals for Spearman's rho are now computed using broom package. RVAideMemoire package is thus removed from dependencies.
  • 95% confidence intervals for partial eta- and omega-squared for ggbetweenstats function are now computed using sjstats package, which allows bootstrapping. apaTables and userfriendlyscience packages are thus removed from dependencies.

ggstatsplot 0.0.1

  • First release of the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.