Description Usage Arguments Details Value See Also Examples
tidy_corrm()
is a generic function with the purpose to take a
dataset and reshape it to a long-table format that can be plotted with
ggcorrm()
.
1 2 3 4 5 6 7 8 9 10 11 12 |
data |
For |
... |
Further arguments (currently ignored in |
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
|
tidy_corrm()
is a generic S3 method that reshapes raw data for a
correlation plot to a long-table format that can be plotted with
ggcorrm()
. The default method takes a data.frame
or matrix
and
creates a tibble with all combinations of all numeric variables in the
dataset that are labelled with their column names (or, alternatively, a
vector with new labels) in the order of their appearance in the raw data.
All other variables are appended to the reshaped data.frame and can be
accessed in the plots.
By default, the data enter the plot unchanged (rescale = "as_is"
), but
it is also possible to scale and center using their standard deviation
(rescale = "by_sd"
) or to rescale them into the range from 0 to 1
(rescale = "by_range"
).
An additional variable called .corr
with the bivariate correlation of the
two variables (by default, Pearson correlation, see cor())
is appended to the dataset. This variable can e.g. be used to specify the
colour or fill of geoms conditional of the strength of the correlation (see
examples in ggcorrm()
). If the correlations displayed with
lotri_corrtext()
or utri_corrtext()
are separated by groups, it may
make sense to also calculate .corr
separately for these groups. In this
case, it is possible to specify a grouping variable for the calculation of
.corr
using corr_group
.
In many cases, the columns of the data.frame
used to construct the
correlation matrix belong to different groups of variables. As the input
for tidy_corrm()
is based on a wide table format, it is often not easily
possible to include this information as an additional column in the raw
data. There are two ways to include variable-specific information after
the fact: a) tidy_corrm()
can be called directly, and its output can be
modified manually before passing it to ggcorrm()
or b) the mutates
argument can be used to pass a list of named quosures created with
rlang::quos() that contain a set of mutating
operations based on regular dplyr::mutate()
syntax that are evaluated
inside the reshaped dataset (see examples). For the standard column names
of tidy_corr
objects see the Value section.
An object of class tidy_corrm
(a tibble with structured correlation
data) containing the following columns:
Name of the variable on the x-axis in the order of appearance in the raw data (ordered factor).
Name of the variable on the y-axis in the order of appearance in the raw data (ordered factor)
Data of the variable on the x axis (numeric).
Data of the variable on the y axis (numeric).
Type of panel (character, "utri"
, "lotri"
or "dia"
).
Correlation between x and y for the respective panel/group,
calculated with cor() using the method specified by
corr_method
and optionally within the groups specified with corr_group
(numeric).
grouping variable for .corr
(1 for all observations if
no groups are specified).
All other columns specified in the dataset and/or
created via mutates
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## Not run:
if(interactive()){
# general shape of the output
corrdat <- tidy_corrm(drosera)
head(corrdat)
# relabeling variables
corrdat1 <- tidy_corrm(drosera,
labels = c("Some", "very", "nice", "labels"))
head(corrdat1)
# use of mutates argument
corrdat2 <- tidy_corrm(
drosera,
mutates = quos(
organ = ifelse(substr(var_x, 1, 1) == "p", "petiole", "leaf"),
dimension = ifelse(grepl("width", var_x), "width", "length")
)
)
head(corrdat2)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.