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",
tr = 0.2,
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,
...
)
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.
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.
Character, "upper"
(default), "lower"
, or "full"
,
display full matrix, lower triangular or upper triangular matrix.
A character specifying the type of statistical approach. Four possible options:
"parametric"
"nonparametric"
"robust"
"bayes"
Corresponding abbreviations are also accepted: "p"
(for parametric),
"np"
(for nonparametric), "r"
(for robust), or "bf"
(for Bayesian).
Trim level for the mean when carrying out robust
tests. In case
of an error, try reducing the value of tr
, which is by default set to
0.2
. Lowering the value might help.
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.
Number of digits after decimal point (should be an integer)
(Default: k = 2L
).
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"
.
Scalar between 0
and 1
. If unspecified, the defaults
return 95%
confidence/credible intervals (0.95
).
A number between 0.5
and 2
(default 0.707
), the prior
width to use in calculating Bayes factors and posterior estimates.
Adjustment method for p-values for multiple
comparisons. Possible methods are: "holm"
(default), "hochberg"
,
"hommel"
, "bonferroni"
, "BH"
, "BY"
, "fdr"
, "none"
.
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: corr
, method
, p.mat
, sig.level
, ggtheme
, colors
, lab
,
pch
, legend.title
, digits
.
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)
.
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)
.
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.
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_
variants of all primary functions. Default is NULL
. The argument should
be entered as a ggplot2
function or a list of ggplot2
functions.
The text for the plot title.
The text for the plot subtitle. Will work only if
results.subtitle = FALSE
.
The text for the plot caption.
Currently ignored.
https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcorrmat.html
# NOT RUN {
# for reproducibility
set.seed(123)
# if `cor.vars` not specified, all numeric variables used
ggstatsplot::ggcorrmat(iris)
# to get the correlation matrix
# 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"
)
# to get the correlation analyses results in a dataframe
ggstatsplot::ggcorrmat(
data = ggplot2::msleep,
cor.vars = sleep_total:bodywt,
partial = TRUE,
output = "dataframe"
)
# }
Run the code above in your browser using DataLab