Helper function for ggstatsplot::ggcorrmat to apply this function across multiple levels of a given factor and combining the resulting plots using ggstatsplot::combine_plots.

  cor.vars = NULL,
  cor.vars.names = NULL,
  title.prefix = NULL,
  output = "plot",
  plotgrid.args = list(),
  title.text = NULL,
  title.args = list(size = 16, fontface = "bold"),
  caption.text = NULL,
  caption.args = list(size = 10),
  sub.text = NULL,
  sub.args = list(size = 12)



Dataframe from which variables specified are preferentially to be taken.


List of variables for which the correlation matrix is to be computed and visualized. If NULL (default), all numeric variables from data will be used.


Optional list of names to be used for cor.vars. The names should be entered in the same order.


A single grouping variable (can be entered either as a bare name x or as a string "x").


Character string specifying the prefix text for the fixed plot title (name of each factor level) (Default: NULL). If NULL, the variable name entered for grouping.var will be used.


Character that decides expected output from this function. If "plot", the visualization matrix will be returned. If "dataframe" (or literally anything other than "plot"), a dataframe containing all details from statistical analyses (e.g., correlation coefficients, statistic values, p-values, no. of observations, etc.) will be returned.


Arguments passed on to ggcorrmat


Character, "full" (default), "upper" or "lower", display full matrix, lower triangular or upper triangular matrix.


The visualization method of correlation matrix to be used. Allowed values are "square" (default) or "circle".


Significance level (Default: 0.05). If the p-value in p-value matrix is bigger than sig.level, then the corresponding correlation coefficient is regarded as insignificant and flagged as such in the plot. Relevant only when output = "plot".


What adjustment for multiple tests should be used? ("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"). See stats::p.adjust for details about why to use "holm" rather than "bonferroni"). Default is "none". If adjusted p-values are displayed in the visualization of correlation matrix, the adjusted p-values will be used for the upper triangle, while unadjusted p-values will be used for the lower triangle of the matrix.


A vector of 3 colors for low, mid, and high correlation values. If set to NULL, manual specification of colors will be turned off and 3 colors from the specified palette from package will be selected.


Decides the point shape to be used for insignificant correlation coefficients (only valid when insig = "pch"). Default: pch = "cross".


A list of additional (mostly aesthetic) arguments that will be passed to ggcorrplot::ggcorrplot function. The list should avoid any of the following arguments since they are already internally being used by ggstatsplot: corr, method, p.mat, sig.level, ggtheme, colors, matrix.type, lab, pch, legend.title, digits.


Decides whether messages references, notes, and warnings are to be displayed (Default: TRUE).


Type of association between paired samples required (""parametric": Pearson's product moment correlation coefficient" or ""nonparametric": Spearman's rho" or ""robust": percentage bend correlation coefficient" or ""bayes": Bayes Factor for Pearson's r"). Corresponding abbreviations are also accepted: "p" (for parametric/pearson), "np" (nonparametric/spearman), "r" (robust), "bf" (for bayes factor), resp.


bending constant (Default: 0.1). For more, see ?WRS2::pbcor.


Number of digits after decimal point (should be an integer) (Default: k = 2).


Scalar between 0 and 1. If unspecified, the defaults return 95% lower and upper confidence intervals (0.95).


A number between 0.5 and 2 (default 0.707), the prior width to use in calculating Bayes factors.


Name of package from which the palette is desired as string or symbol.


Name of palette as string or symbol.


A function, ggplot2 theme name. Default value is ggplot2::theme_bw(). Any of the ggplot2 themes, or themes from extension packages are allowed (e.g., ggthemes::theme_fivethirtyeight(), hrbrthemes::theme_ipsum_ps(), etc.).


Logical that decides whether theme_ggstatsplot theme elements are to be displayed along with the selected ggtheme (Default: TRUE). theme_ggstatsplot is an opinionated theme layer that override some aspects of the selected ggtheme.


A ggplot component to be added to the plot prepared by ggstatsplot. This argument is primarily helpful for grouped_ variant of the current function. Default is NULL. The argument should be entered as a function.


The text for the plot subtitle. Will work only if results.subtitle = FALSE.


The text for the plot caption.


A list of additional arguments to cowplot::plot_grid.


String or plotmath expression to be drawn as title for the combined plot.


A list of additional arguments provided to title, caption and sub, resp.


String or plotmath expression to be drawn as the caption for the combined plot.


A list of additional arguments provided to title, caption and sub, resp.


The label with which the combined plot should be annotated. Can be a plotmath expression.


A list of additional arguments provided to title, caption and sub, resp.


Correlation matrix plot or a dataframe containing results from pairwise correlation tests. The package internally uses ggcorrplot::ggcorrplot for creating the visualization matrix, while the correlation analysis is carried out using the correlation::correlation function.


See also


# \donttest{ # for reproducibility set.seed(123) # for plot ggstatsplot::grouped_ggcorrmat( data = iris, grouping.var = Species, type = "robust", p.adjust.method = "holm" )
# for dataframe ggstatsplot::grouped_ggcorrmat( data = ggplot2::msleep, grouping.var = vore, type = "bayes", output = "dataframe" )
#> Warning: Series not converged.
#> Warning: Series not converged.
#> Warning: Series not converged.
#> Warning: Series not converged.
#> # A tibble: 60 x 13 #> vore parameter1 parameter2 rho ci_low ci_high pd rope_percentage #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 carni sleep_total sleep_rem 0.850 0.641 0.961 1 0 #> 2 carni sleep_total sleep_cycle 0.213 -0.359 0.750 0.692 0.176 #> 3 carni sleep_total awake -1.00 -1.00 -1.00 1 0 #> 4 carni sleep_total brainwt -0.389 -0.787 0.0205 0.897 0.115 #> 5 carni sleep_total bodywt -0.371 -0.654 -0.0701 0.96 0.0875 #> 6 carni sleep_rem sleep_cycle 0.0727 -0.518 0.610 0.552 0.192 #> 7 carni sleep_rem awake -0.843 -0.958 -0.660 1 0 #> 8 carni sleep_rem brainwt -0.316 -0.763 0.244 0.785 0.157 #> 9 carni sleep_rem bodywt -0.366 -0.766 0.0411 0.887 0.116 #> 10 carni sleep_cycle awake -0.214 -0.741 0.356 0.692 0.182 #> prior_distribution prior_location prior_scale bf nobs #> <chr> <dbl> <dbl> <dbl> <int> #> 1 cauchy 0 0.707 112. 10 #> 2 cauchy 0 0.707 0.714 5 #> 3 cauchy 0 0.707 NA 19 #> 4 cauchy 0 0.707 1.13 9 #> 5 cauchy 0 0.707 1.72 19 #> 6 cauchy 0 0.707 0.621 5 #> 7 cauchy 0 0.707 112. 10 #> 8 cauchy 0 0.707 0.848 6 #> 9 cauchy 0 0.707 1.03 10 #> 10 cauchy 0 0.707 0.714 5 #> # ... with 50 more rows
# }