tidiers | R Documentation |
These functions return tibbles that summarize
an object of class 'tbl_ord'. tidy()
output contains one row per
artificial coordinate and glance()
output contains one row for the whole
ordination.
## S3 method for class 'tbl_ord' tidy(x, ...) ## S3 method for class 'tbl_ord' glance(x, ...) ## S3 method for class 'tbl_ord' fortify(model, data, ..., .matrix = "dims", elements = "all")
x, model |
An object of class 'tbl_ord'. |
... |
Additional arguments allowed by generics; currently ignored. |
data |
Passed to generic methods; currently ignored. |
.matrix |
A character string partially matched (lowercase) to several
indicators for one or both matrices in a matrix decomposition used for
ordination. The standard values are |
elements |
Character vector; which elements of each factor for which to
render graphical elements. One of |
Three generics popularized by the ggplot2 and broom packages make use of the augmentation methods:
The generics::tidy()
method
summarizes information about model components, which here are the
artificial coordinates created by ordinations. The output can be passed to
ggplot2::ggplot()
to generate scree plots.
The returned columns are
name
: (the name of) the coordinate
other columns extracted from the model, usually a single additional column of the singular or eigen values
inertia
: the multidimensional variance
prop_var
: the proportion of inertia
quality
: the cumulative proportion of variance
The generics::glance()
method
reports information about the entire model, here always treated as one of a
broader class of ordination models.
The returned columns are
rank
: the rank of the ordination model, i.e. the number of ordinates
n.row
,n.col
: the dimensions of the decomposed matrix
inertia
: the total inertia in the ordination
prop.var.*
: the proportion of variance in the first 2 ordinates
class
: the class of the wrapped model object
The ggplot2::fortify()
method
augments and collapses row and/or column data, depending on .matrix
and
.element
, into a single tibble, in preparation for ggplot2::ggplot()
.
Its output resembles that of generics::augment()
, though rows in the
output may correspond to rows, columns, or both of the original data. If
.matrix
is passed "rows"
, "cols"
, or "dims"
(for both), then
fortify()
returns a tibble whose fields are obtained, in order, via
get_*()
, recover_aug_*()
, and annotation_*()
.
The tibble is assigned a "coordinates"
attribute whose value is obtained
via get_coord()
. This facilitates some downstream functionality that relies
on more than those coordinates used as position aesthetics in a biplot, in
particular stat_spantree()
.
A tibble.
augmentation methods that must interface with tidiers.
# illustrative ordination: PCA of iris data iris_pca <- ordinate(iris, ~ prcomp(., center = TRUE, scale. = TRUE), seq(4L)) # use `tidy()` to summarize distribution of inertia tidy(iris_pca) # this facilitates scree plots tidy(iris_pca) %>% ggplot(aes(x = name, y = prop_var)) + geom_col() + scale_y_continuous(labels = scales::percent) + labs(x = NULL, y = "Proportion of variance") # use `fortify()` to prepare either matrix factor for `ggplot()` fortify(iris_pca, .matrix = "V") %>% ggplot(aes(x = name, y = PC1)) + geom_col() + coord_flip() + labs(x = "Measurement") iris_pca %>% fortify(.matrix = "U") %>% ggplot(aes(x = PC1, fill = Species)) + geom_histogram() + labs(y = NULL) # ... or to prepare both for `ggbiplot()` fortify(iris_pca) # use `glance()` to summarize the model as an ordination glance(iris_pca) # this enables comparisons to other models rbind( glance(ordinate(subset(iris, Species == "setosa"), prcomp, seq(4L))), glance(ordinate(subset(iris, Species == "versicolor"), prcomp, seq(4L))), glance(ordinate(subset(iris, Species == "virginica"), prcomp, seq(4L))) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.