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,
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)
)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
matrix.typeCharacter, "full" (default), "upper" or "lower",
display full matrix, lower triangular or upper triangular matrix.
typeA character string indicating which correlation coefficient is to
be computed: "pearson" (Pearson's r), "spearman" (Spearman's rho),
"robust" (percentage bend correlation (see ?WRS2::pball)) or "bayes",
which would compute Bayes Factor for Pearson's r.
Abbreviations will also work: "p" (for parametric), "np"
(nonparametric), "r" (robust), "bf" (Bayes Factor).
betaA numeric bending constant for percentage bend robust correlation
coefficient (Default: 0.1).
sig.levelSignificance 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".
p.adjust.methodWhat 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.
colorsA 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.
captionThe text for the plot caption. If NULL, a default caption
will be shown.
pchDecides the glyphs (read point shapes) to be used for
insignificant correlation coefficients (only valid when insig = "pch").
Default value is pch = 4.
ggcorrplot.argsA 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.
ggthemeA 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.layerLogical 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.
methodSmoothing method (function) to use, accepts either
NULL or a character vector, e.g. "lm", "glm", "gam", "loess"
or a function, e.g. MASS::rlm or mgcv::gam, stats::lm, or stats::loess.
"auto" is also accepted for backwards compatibility. It is equivalent to
NULL.
For method = NULL the smoothing method is chosen based on the
size of the largest group (across all panels). stats::loess() is
used for less than 1,000 observations; otherwise mgcv::gam() is
used with formula = y ~ s(x, bs = "cs") with method = "REML". Somewhat anecdotally,
loess gives a better appearance, but is \(O(N^{2})\) in memory,
so does not work for larger datasets.
If you have fewer than 1,000 observations but want to use the same gam()
model that method = NULL would use, then set
method = "gam", formula = y ~ s(x, bs = "cs").
kNumber of digits after decimal point (should be an integer)
(Default: k = 2).
conf.levelScalar between 0 and 1. If unspecified, the defaults return
95% lower and upper confidence intervals (0.95).
bf.priorA number between 0.5 and 2 (default 0.707), the prior
width to use in calculating Bayes factors.
subtitleThe text for the plot subtitle. Will work only if
results.subtitle = FALSE.
messagesDecides whether messages references, notes, and warnings are
to be displayed (Default: TRUE).
packageName of package from which the palette is desired as string or symbol.
paletteName of palette as string or symbol.
directionEither 1 or -1. If -1 the palette will be reversed.
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.
https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/ggcorrmat.html
# NOT RUN {
# 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"
)
# }
Run the code above in your browser using DataLab