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
.
grouped_ggcorrmat(
data,
cor.vars = NULL,
grouping.var,
output = "plot",
plotgrid.args = list(),
annotation.args = list(),
...
)
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.
A single grouping variable (can be entered either as a
bare name x
or as a string "x"
).
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.
A list
of additional arguments passed to
patchwork::wrap_plots
, except for guides
argument which is already
separately specified here.
A list
of additional arguments passed to
patchwork::plot_annotation
.
Arguments passed on to ggcorrmat
cor.vars.names
Optional list of names to be used for cor.vars
. The
names should be entered in the same order.
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
A character specifying the type of statistical approach:
"parametric"
"nonparametric"
"robust"
"bayes"
You can specify just the initial letter.
tr
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.
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 and posterior estimates. In
addition to numeric arguments, several named values are also recognized:
"medium"
, "wide"
, and "ultrawide"
, corresponding to r scale values
of 1/2, sqrt(2)/2, and 1, respectively. In case of an ANOVA, this value
corresponds to scale for fixed effects.
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 ggplot2
theme. Default value is
ggstatsplot::theme_ggstatsplot()
. Any of the ggplot2
themes (e.g.,
ggplot2::theme_bw()
), or themes from extension packages are allowed
(e.g., ggthemes::theme_fivethirtyeight()
, hrbrthemes::theme_ipsum_ps()
,
etc.).
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.
For more details, see: https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcorrmat.html
# NOT RUN {
# for reproducibility
set.seed(123)
library(ggstatsplot)
# for plot
if (require("ggcorrplot")) {
grouped_ggcorrmat(
data = iris,
grouping.var = Species,
type = "robust",
p.adjust.method = "holm",
plotgrid.args = list(ncol = 1),
annotation.args = list(tag_levels = "i")
)
}
# for dataframe
grouped_ggcorrmat(
data = ggplot2::msleep,
grouping.var = vore,
type = "bayes",
output = "dataframe"
)
# }
Run the code above in your browser using DataLab