ternary_diagram: Ternary diagram for compositional data (D = 3)

View source: R/ternary_diagram.R

ternary_diagramR Documentation

Ternary diagram for compositional data (D = 3)

Description

Create a ternary diagram from compositional data with exactly three parts. Optionally center and/or scale the data in log-ratio coordinates, color points by group, and overlay the first two principal component directions computed in ilr coordinates.

Usage

ternary_diagram(
  X,
  group = NULL,
  center = FALSE,
  scale = FALSE,
  show_pc = FALSE
)

Arguments

X

A numeric matrix or data frame with exactly three columns (the parts of the composition). Values should be positive. Column names (if present) are used as corner labels.

group

Optional. A factor or character vector of length nrow(X) used to color points by group.

center

Logical. If TRUE, center the log-ratio coordinates before plotting. Default is FALSE.

scale

Logical or numeric. If FALSE, no scaling is applied. If TRUE, log-ratio coordinates are scaled by their empirical standard deviations. If a single positive numeric value is supplied, centered log-ratio coordinates are multiplied by that value, so values larger than 1 increase visual spread and values between 0 and 1 shrink it.

show_pc

Logical. If TRUE, overlay the first two principal component directions computed on log-ratio coordinates (recommended: ilr). Default is FALSE.

Details

This function is kept as a convenient wrapper around the modular ternary API: ternary_frame(), ternary_plot(), add_ternary_points(), and add_ternary_pc().

Value

A ggplot2 object.

See Also

ternary_frame, ternary_plot, add_ternary_points, add_ternary_pc

Examples

X <- milk_cows[, 5:7]
group <- milk_cows$group

ternary_diagram(X, group = group)
ternary_diagram(X, group = group, center = TRUE, scale = TRUE)
ternary_diagram(X, group = group, center = TRUE, scale = 1.5)
ternary_diagram(X, show_pc = TRUE)


coda.plot documentation built on April 12, 2026, 9:06 a.m.