Maturing lifecycle

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.

ggcorrmat(
  data,
  cor.vars = NULL,
  cor.vars.names = NULL,
  output = "plot",
  matrix.type = "upper",
  type = "parametric",
  beta = 0.1,
  partial = FALSE,
  k = 2L,
  sig.level = 0.05,
  conf.level = 0.95,
  bf.prior = 0.707,
  p.adjust.method = "holm",
  pch = "cross",
  ggcorrplot.args = list(method = "square", outline.color = "black"),
  package = "RColorBrewer",
  palette = "Dark2",
  colors = c("#E69F00", "white", "#009E73"),
  ggtheme = ggplot2::theme_bw(),
  ggstatsplot.layer = TRUE,
  ggplot.component = NULL,
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  ...
)

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.

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.

matrix.type

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

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

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.

k

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

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

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

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.

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

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.

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.

title

The text for the plot title.

subtitle

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

caption

The text for the plot caption.

...

Currently ignored.

References

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

See also

Examples

# \donttest{ # for reproducibility set.seed(123) # if `cor.vars` not specified, all numeric variables used ggstatsplot::ggcorrmat(iris)
# to get the correlalogram # note that the function will run even if the vector with variable names is # not of same length as the number of variables ggstatsplot::ggcorrmat( data = ggplot2::msleep, type = "robust", cor.vars = sleep_total:bodywt, cor.vars.names = c("total sleep", "REM sleep"), matrix.type = "lower" )
#> Warning: Mismatch between number of variables and names.
# to get the correlation analyses results in a dataframe ggstatsplot::ggcorrmat( data = ggplot2::msleep, cor.vars = sleep_total:bodywt, partial = TRUE, output = "dataframe" )
#> # A tibble: 15 x 10 #> parameter1 parameter2 estimate conf.low conf.high statistic df #> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <int> #> 1 sleep_total sleep_rem 0.314 -0.0520 0.606 1.75 28 #> 2 sleep_total sleep_cycle -0.0225 -0.380 0.341 -0.119 28 #> 3 sleep_total awake -1 -1 -1 -Inf 28 #> 4 sleep_total brainwt -0.0970 -0.442 0.273 -0.516 28 #> 5 sleep_total bodywt -0.179 -0.506 0.194 -0.961 28 #> 6 sleep_rem sleep_cycle -0.0766 -0.425 0.292 -0.407 28 #> 7 sleep_rem awake 0.0560 -0.311 0.408 0.297 28 #> 8 sleep_rem brainwt 0.0857 -0.283 0.433 0.455 28 #> 9 sleep_rem bodywt -0.0341 -0.390 0.330 -0.181 28 #> 10 sleep_cycle awake -0.00479 -0.364 0.356 -0.0253 28 #> 11 sleep_cycle brainwt 0.801 0.620 0.901 7.08 28 #> 12 sleep_cycle bodywt -0.0949 -0.440 0.275 -0.505 28 #> 13 awake brainwt -0.0957 -0.441 0.274 -0.509 28 #> 14 awake bodywt -0.448 -0.696 -0.104 -2.65 28 #> 15 brainwt bodywt 0.252 -0.119 0.561 1.38 28 #> p.value method n.obs #> <dbl> <chr> <int> #> 1 1 Pearson 30 #> 2 1 Pearson 30 #> 3 0 Pearson 30 #> 4 1 Pearson 30 #> 5 1 Pearson 30 #> 6 1 Pearson 30 #> 7 1 Pearson 30 #> 8 1 Pearson 30 #> 9 1 Pearson 30 #> 10 1 Pearson 30 #> 11 0.00000148 Pearson 30 #> 12 1 Pearson 30 #> 13 1 Pearson 30 #> 14 0.170 Pearson 30 #> 15 1 Pearson 30
# }