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(grouping.var, title.prefix = "Group", data, cor.vars,
cor.vars.names = NULL, output = "plot", type = "full",
method = "square", corr.method = "pearson", exact = FALSE,
continuity = TRUE, beta = 0.2, digits = 2, sig.level = 0.05,
hc.order = FALSE, hc.method = "complete", lab = TRUE,
colors = c("#E69F00", "white", "#009E73"), outline.color = "black",
ggtheme = ggplot2::theme_gray, ggstatsplot.theme = TRUE,
subtitle = NULL, caption = NULL, caption.default = TRUE,
lab.col = "black", lab.size = 5, insig = "pch", pch = 4,
pch.col = "black", pch.cex = 11, tl.cex = 12, tl.col = "black",
tl.srt = 45, axis.text.x.margin.t = 0, axis.text.x.margin.r = 0,
axis.text.x.margin.b = 0, axis.text.x.margin.l = 0,
legend.title.margin = TRUE, t.margin = unit(0, "mm"), b.margin = unit(3,
"mm"), messages = TRUE, ...)
Grouping variable.
Character specifying the prefix text for the fixed plot
title (name of each factor level) (Default: "Group"
).
Dataframe from which variables specified are preferentially to be taken.
List of vairables for which the correlation matrix is to be computed and visualized.
Optional list of names to be used for cor.vars
. The
names should be entered in the same order.
Expected output from this function: "plot"
(visualization
matrix) or "correlations"
(correlation matrix) or "p-values"
(matrix of
p-values).
Character, "full"
(default), "upper"
or "lower"
, display
full matrix, lowe triangular or upper triangular matrix.
Character argument that decides the visualization method of
correlation matrix to be used. Allowed values are "square"
(default),
"circle"
A character string indicating which correlation
coefficient is to be computed ("pearson"
(default) or "kendall"
or
"spearman"
). "robust"
can also be entered but only if output
argument
is set to either "correlations"
or "p-values"
. The robust correlation
used is percentage bend correlation (see ?WRS2::pball
). Abbreviations
will not work.
A logical indicating whether an exact p-value should be
computed. Used for Kendall's tau and Spearman's rho. For more details,
see ?stats::cor.test
.
A logical. If TRUE
, a continuity correction is used for
Kendall's tau and Spearman's rho when not computed exactly (Default:
TRUE
).
A numeric bending constant for robust correlation coefficient
(Default: 0.2
).
Decides the number of decimal digits to be added into the plot
(Default: 2
).
Significance level (Dafault: 0.05
). If the p-value in
p-mat (p-value matrix) is bigger than sig.level
, then the corresponding
correlation coefficient is regarded as insignificant.
Logical value. If TRUE
, correlation matrix will be
hc.ordered using hclust
function (Default is FALSE
).
The agglomeration method to be used in hclust
(see
?hclust
).
Logical value. If TRUE
, correlation coefficient values will be
displayed in the plot.
A vector of 3 colors for low, mid, and high correlation values.
The outline color of square or circle. Default value is
"gray"
.
A function, ggplot2
theme name. Default value is
ggplot2::theme_gray
. Allowed values are the official ggplot2
themes,
including theme_bw
, theme_minimal
, theme_classic
, theme_void
, etc.
A logical. Decides whether default theme for
ggstatsplot
, which is theme_mprl
, is to be overlaid on the entered
theme (Default: ggstatsplot.theme = TRUE
).
The text for the plot subtitle.
The text for the plot caption. If not specified (if it is
NULL
, i.e.), a default caption will be shown.
Logical decides whether the default caption should be shown.
Color to be used for the correlation coefficient labels
(applicable only when lab = TRUE
).
Size to be used for the correlation coefficient labels
(applicable only when lab = TRUE
).
Character used to show specialized insignificant correlation
coefficients ("pch"
(default) or "blank"
). If "blank"
, the
corresponding glyphs will be removed; if "pch" is used, characters (see
?pch
for details) will be added on the corresponding glyphs.
Decides the glyphs (read point shapes) to be used for insignificant correlation
coefficients (only valid when insig = "pch"
). Default value is pch = 4
.
The color and the cex (size) of pch
(only valid when
insig = "pch"
). Defaults are pch.col = "#F0E442"
and pch.cex = 10
.
The size, the color, and the string rotation of text label (variable names, i.e.).
Margins between x-axis and the variable name texts (t: top, r: right, b:
bottom, l:left), especially useful in case the names are slanted, i.e. when the tl.srt is
between 45
and 75
(Defaults: 0
, 0
, 0
, 0
, resp.).
Logical indicating whether to adjust the margin between legend title and the
colorbar (Default: TRUE
).
Margins in grid units. For more details, see
?grid::unit()
.
Decides whether messages references, notes, and warnings are
to be displayed (Default: TRUE
).
Arguments passed on to combine_plots
String or plotmath expression to be drawn as title for the combined plot.
Text color for title.
Point size of title text.
Vertical justification for title. Default = 0.5 (centered on y). 0 = baseline at y, 1 = ascender at y.
Horizontal justification for title. Default = 0.5 (centered on x). 0 = flush-left at x, 1 = flush-right.
The font face ("plain", "bold", etc.) for title.
String or plotmath expression to be drawn as the caption for the combined plot.
Text color for caption.
Point size of title text.
Vertical justification for caption. Default = 0.5
(centered on y). 0
= baseline at y, 1
= ascender at y.
Horizontal justification for caption. Default = 0.5
(centered on x). 0
= flush-left at x, 1
= flush-right.
The font face ("plain"
, "bold"
, "italic"
,
"bold.italic"
) for caption.
The label with which the combined plot should be annotated. Can be a plotmath expression.
Text color for annotation label.
Point size of annotation text.
The x position of annotation label.
The y position of annotation label.
Horizontal justification for annotation label.
Vertical justification for annotation label.
Vertical padding. The total vertical space added to the label, given in grid units. By default, this is added equally above and below the label. However, by changing the y and vjust parameters, this can be changed.
The font face ("plain"
, "bold"
, "italic"
,
"bold.italic"
) for the annotation label.
Angle at which annotation label is to be drawn.
Line height of annotation label.
Numerical vector of relative columns heights while combining (title, plot, caption).
Numerical vector of relative columns heights while combining (title, plot).
Numerical vector of relative columns heights while combining (plot, caption).
# NOT RUN {
# for getting correlations
ggstatsplot::grouped_ggcorrmat(
data = datasets::iris,
grouping.var = Species,
cor.vars = Sepal.Length:Petal.Width,
output = "plot",
nrow = 3,
ncol = 1
)
# for getting correlations
ggstatsplot::grouped_ggcorrmat(
data = datasets::iris,
grouping.var = Species,
cor.vars = Sepal.Length:Petal.Width,
output = "correlations"
)
# }
Run the code above in your browser using DataLab