Maturing lifecycle

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

grouped_ggcorrmat(
  data,
  cor.vars = NULL,
  cor.vars.names = NULL,
  grouping.var,
  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)
)

Arguments

data

Dataframe from which variables specified are preferentially to be taken.

cor.vars

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.

cor.vars.names

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

grouping.var

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

title.prefix

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.

output

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

partial

Can be TRUE for partial correlations. For Bayesian partial correlations, "full" instead of pseudo-Bayesian partial correlations (i.e., Bayesian correlation based on frequentist partialization) are returned.

matrix.type

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

sig.level

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

colors

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.

pch

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

ggcorrplot.args

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: corr, method, p.mat, sig.level, ggtheme, colors, lab, pch, legend.title, digits.

type

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.

beta

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

k

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

conf.level

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

bf.prior

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

p.adjust.method

Adjustment method for p-values for multiple comparisons. Possible methods are: "holm" (default), "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none".

package

Name of the package from which the given palette is to be extracted. The available palettes and packages can be checked by running View(paletteer::palettes_d_names).

palette

Name of the package from which the given palette is to be extracted. The available palettes and packages can be checked by running View(paletteer::palettes_d_names).

ggtheme

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

ggstatsplot.layer

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.

ggplot.component

A ggplot component to be added to the plot prepared by ggstatsplot. This argument is primarily helpful for grouped_ variants of all primary functions. Default is NULL. The argument should be entered as a ggplot2 function or a list of ggplot2 functions.

subtitle

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

caption

The text for the plot caption.

plotgrid.args

A list of additional arguments to cowplot::plot_grid.

title.text

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

title.args

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

caption.text

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

caption.args

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

sub.text

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

sub.args

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

References

https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcorrmat.html

See also

Examples

# \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 14 #> vore parameter1 parameter2 estimate conf.low conf.high pd #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> #> 1 carni sleep_total sleep_rem 0.845 0.641 0.961 1 #> 2 carni sleep_total sleep_cycle 0.204 -0.351 0.764 0.698 #> 3 carni sleep_total awake -1.00 -1.00 -1.00 1 #> 4 carni sleep_total brainwt -0.382 -0.759 0.0549 0.895 #> 5 carni sleep_total bodywt -0.379 -0.662 -0.0654 0.960 #> 6 carni sleep_rem sleep_cycle 0.0548 -0.534 0.587 0.562 #> 7 carni sleep_rem awake -0.848 -0.962 -0.678 1 #> 8 carni sleep_rem brainwt -0.308 -0.760 0.252 0.804 #> 9 carni sleep_rem bodywt -0.371 -0.716 0.0694 0.899 #> 10 carni sleep_cycle awake -0.205 -0.754 0.373 0.690 #> rope.percentage prior.distribution prior.location prior.scale bayes.factor #> <dbl> <chr> <dbl> <dbl> <dbl> #> 1 0 cauchy 0 0.707 112. #> 2 0.168 cauchy 0 0.707 0.714 #> 3 0 cauchy 0 0.707 NA #> 4 0.116 cauchy 0 0.707 1.13 #> 5 0.078 cauchy 0 0.707 1.72 #> 6 0.206 cauchy 0 0.707 0.621 #> 7 0.0118 cauchy 0 0.707 112. #> 8 0.136 cauchy 0 0.707 0.848 #> 9 0.124 cauchy 0 0.707 1.03 #> 10 0.165 cauchy 0 0.707 0.714 #> method n.obs #> <chr> <int> #> 1 Bayesian Pearson 10 #> 2 Bayesian Pearson 5 #> 3 Bayesian Pearson 19 #> 4 Bayesian Pearson 9 #> 5 Bayesian Pearson 19 #> 6 Bayesian Pearson 5 #> 7 Bayesian Pearson 10 #> 8 Bayesian Pearson 6 #> 9 Bayesian Pearson 10 #> 10 Bayesian Pearson 5 #> # ... with 50 more rows
# }