Description Usage Arguments Details Value See Also Examples
ggcorrm()
initializes a ggcorrm
object (inheriting from
class ggplot
). It can be called either using the raw data for the
correlation plot as input, which is then internally passed to
tidy_corrm()
, or with a prepared correlation dataset of class
tidy_corrm
.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
data |
Dataset used to compute the correlation matrix. Can be either a
|
mapping |
Set of aesthetic mappings created by aes that
are passed on to subsequent layers. |
labels |
(Optional) character vector or function. If a character, must
contain labels for the names of all numeric columns that are used to
replace the column names in the plot axis and text labels and must be of
the same length as the number of numeric columns displayed in the plot. If
a function, must take the original names of the numeric columns as an
argument and return a character vector with the same length. Defaults to
|
rescale |
character string specifying the type of transformation
performed on the numeric variables in the plot. The standard argument
|
corr_method |
character string with the correlation method passed to
|
corr_group |
|
mutates |
(Optional) list of named quosures created with
rlang::quos(). Can be any expressions that specify changes to the
|
bg_dia |
(Optional) background color specification for the diagonal
panels. Either a character string with a hexadecimal color code, a
character string specifying a color name in colors, or
an integer specifying a position in palette. The
default value of |
bg_lotri |
(Optional) background color specification for the panels in
the lower triangle. Either a character string with a hexadecimal color
code, a character string specifying a color name in
colors, or an integer specifying a position in
palette. The default value of |
bg_utri |
(Optional) background color specification for the panels in
the lower triangle. Either a character string with a hexadecimal color
code, a character string specifying a color name in
colors, or an integer specifying a position in
palette. The default value of |
facet_arg |
(Optional) list with additional arguments for the facet_grid() call that defines the structure of the panels of the correlation matrix. |
ggcorrm
creates the initial correlation plot object containing
information about panel placement, correlations, themes etc. Its output is
a modified empty ggplot
object with appropriate facet and theme
specifications. If a tidy_corrm
object is supplied as data
, it will be
directly plotted without invoking tidy_corrm()
, else, ggcorrm()
passes
the raw data and additional arguments to tidy_corrm()
before plotting
(see documentation of this function for details).
New layers can be added using standard ggplot2::ggplot_add()
syntax,
though in most cases it will be more useful to add layers using the
corrmorant selector functions which allow to map
geoms to a subset of panels on the plot diagonal, lower or upper triangle
using dia()
, lotri()
or utri()
, respectively (see examples).
bg_dia
, bg_lotri
and bg_utri
allow to specify different background
color settings for the plot diagonal, the lower and the upper triangle of
the correlation plot matrix, respectively. All other graphics settings can
be modified using regular ggplot2 theme syntax, building
upon the corrmorant standard theme (theme_corrm).
facet_arg
allows to change the settings in the ggplot2::facet_grid()
call underlying the facet structure of a corrmorant plot. This is likely
most helpful if you wish to parse facet labels as expressions with
facet_arg = list(labeller = "label_parsed")
.
An object of class ggcorrm
containing the reshaped dataset for the
correlation plot and an empty ggplot
object with appropriate facet and
theme specifications.
tidy_corrm()
for the preparation of tidy corrmorant datasets
corrmorant()
for a fast and easy to use version of ggcorrm()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ## Not run:
if(interactive()){
# correlation matrix for the drosera dataset
ggcorrm(drosera, bg_dia = "grey20") +
lotri(geom_point(alpha = 0.4)) +
utri_corrtext() +
dia_histogram(lower = .3, fill = "grey90", col = 1) +
dia_names(y_pos = .1, col = "white", size = 3)
# drosera data with conditional coloring by Pearson correlation
ggcorrm(drosera, aes(col = .corr, fill = .corr)) +
lotri(geom_point(alpha = 0.6)) +
lotri(geom_smooth(method = "lm", size = 0.3, alpha = 0.6)) +
utri_corrtext() +
dia_density(fill = "grey80", col = 1, lower = .4) +
dia_names(y_pos = .1) +
scale_color_corr(option = "A", aesthetics = c("fill", "color"))
# correlation separated by species
ggcorrm(drosera, aes(col = species, fill = species),
rescale = "by_sd", bg_dia = "grey95") +
lotri(geom_point(alpha = 0.4)) +
lotri(geom_smooth(col = 1, method = "lm")) +
utri_corrtext(nrow = 2) +
dia_density(col = 1, alpha = 0.5, lower = 0.4) +
dia_names(y_pos = 0.15)
# using the 'mutates' argument to color diagonal panels by plant organ
ggcorrm(drosera, rescale = "by_sd",
mutates = quos(organ = ifelse(substr(var_x, 1, 1) == "p",
"Petiole", "Leaf blade"))) +
lotri(geom_point(alpha = 0.4))+
utri_corrtext() +
dia_density(lower = .3,
mapping = aes(fill = organ)) +
dia_names(y_pos = .1,
mapping = aes(col = organ))
# using facet_args and dia_names(parse = TRUE) to parse variable names
data <- matrix(log(1:100), ncol = 5)
ggcorrm(data,
labels = c("gamma", "beta", "alpha[3]", "phi^2", "B~(cm^2)"),
facet_arg = list(labeller = "label_parsed")) +
utri(geom_point()) +
lotri_corrtext() +
dia_names(y_pos = 0.5, parse = TRUE)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.