geom_interpolation {ordr} | R Documentation |
Render interpolation of new rows from columns (or vice-versa)
Description
geom_interpolation()
renders a geometric construction that
interpolates a new data matrix (row or column) element from its entries to
its artificial coordinates.
Usage
geom_interpolation(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
new_data = NULL,
type = c("centroid", "sequence"),
arrow = default_arrow,
...,
point.fill = NA,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
new_data |
A list (best structured as a data.frame)
of row ( |
type |
Character value matched to |
arrow |
Specification for arrows, as created by |
... |
Additional arguments passed to |
point.fill |
Default aesthetics for markers. Set to NULL to inherit from the data's aesthetics. |
na.rm |
Passed to |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Details
Interpolation answers the following question: Given a new data
element that might have appeared as a row (respectively, column) in the
singular-value-decomposed data matrix, where should we expect the marker
for this element to appear in the biplot? The solution is the vector sum of
the column (row) units weighted by their values in the new row (column).
Gower, Gardner–Lubbe, & le Roux (2011) provide two visualizations of this
calculation: a tail-to-head sequence of weighted units (type = "sequence"
), and a centroid of the weighted units scaled by the number of
units (type = "centroid"
).
WARNING:
This layer is appropriate only with axes in standard coordinates (usually
confer_inertia(p = "rows")
) and interpolative
calibration (ggbiplot(axis.type = "interpolative")
).
Biplot layers
ggbiplot()
uses ggplot2::fortify()
internally to produce a single data
frame with a .matrix
column distinguishing the subjects ("rows"
) and
variables ("cols"
). The stat layers stat_rows()
and stat_cols()
simply
filter the data frame to one of these two.
The geom layers geom_rows_*()
and geom_cols_*()
call the corresponding
stat in order to render plot elements for the corresponding factor matrix.
geom_dims_*()
selects a default matrix based on common practice, e.g.
points for rows and arrows for columns.
Aesthetics
geom_interpolation()
requires the custom interpolate
aesthetic, which
tells the internals which columns of the new_data
parameter contain the
variables to be used for interpolation. Except in rare cases, new_data
should contain the same rows or columns as the ordinated data and
interpolate
should be set to name
(procured by augment_ord()
).
geom_interpolation()
additionally understands the following aesthetics
(required aesthetics are in bold):
-
alpha
-
colour
-
linetype
-
size
-
fill
-
shape
-
stroke
-
center
,scale
-
group
References
Gower JC, Gardner–Lubbe S, & le Roux NJ (2011) Understanding Biplots. Wiley, ISBN: 978-0-470-01255-0. https://www.wiley.com/go/biplots
See Also
Other geom layers:
geom_origin()
Examples
iris[, -5] %>%
prcomp(scale = TRUE) %>%
as_tbl_ord() %>%
print() -> iris_pca
iris_pca <- mutate_rows(iris_pca, species = iris$Species)
iris_pca <- augment_ord(iris_pca)
# sample of one of each species, with some missing measurements
new_data <- iris[c(42, 61, 110), seq(5, 1), drop = FALSE]
new_data[3L, "Sepal.Width"] <- NA
new_data[1L, "Petal.Length"] <- NA
print(new_data)
# centroid interpolation method
iris_pca %>%
augment_ord() %>%
mutate_rows(obs = dplyr::row_number()) %>%
mutate_cols(measure = name) %>%
ggbiplot() +
theme_bw() +
scale_color_brewer(type = "qual", palette = 2) +
geom_origin(marker = "cross", alpha = .5) +
geom_cols_interpolation(
aes(center = center, scale = scale, interpolate = name), size = 3,
new_data = new_data, type = "centroid", alpha = .5
) +
geom_rows_text(aes(label = obs, color = species), alpha = .5, size = 3)
# missing an entire variable
new_data$Petal.Length <- NULL
# sequence interpolation method
iris_pca %>%
augment_ord() %>%
mutate_rows(obs = dplyr::row_number()) %>%
mutate_cols(measure = name) %>%
ggbiplot() +
theme_bw() +
scale_color_brewer(type = "qual", palette = 2) +
geom_origin(marker = "circle", alpha = .5) +
geom_cols_interpolation(
aes(center = center, scale = scale, interpolate = name,
linetype = measure),
new_data = new_data, type = "sequence", alpha = .5
) +
geom_rows_text(aes(label = obs, color = species), alpha = .5, size = 3)