tidiers {ordr}R Documentation

Tidiers for 'tbl_ord' objects

Description

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.

Usage

## 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")

Arguments

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 "rows", "cols", and "dims" (for both).

elements

Character vector; which elements of each factor for which to render graphical elements. One of "all" (the default), "active", or any supplementary element type defined by the specific class methods (e.g. "score" for 'factanal', 'lda_ord', and 'cancord_ord' and "intraset" and "interset" for 'cancor_ord').

Details

Three generics popularized by the ggplot2 and broom packages make use of the augmentation methods:

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().

Value

A tibble.

See Also

augmentation methods that must interface with tidiers.

Examples

# 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)))
)

[Package ordr version 0.1.1 Index]