Type: Package
Title: Plots for Compositional Data
Version: 0.1.9
Date: 2025-04-20
Description: Provides a collection of easy-to-use functions for creating visualizations of compositional data using 'ggplot2'. Includes support for common plotting techniques in compositional data analysis.
Depends: R (≥ 3.5), coda.base (≥ 0.5)
License: GPL-2 | GPL-3 [expanded from: GPL]
Encoding: UTF-8
Imports: ggplot2 (≥ 3.5.0), ggtern (≥ 3.5.0)
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-04-20 21:20:17 UTC; marc
Author: Marc Comas-Cufí ORCID iD [aut, cre]
Maintainer: Marc Comas-Cufí <mcomas@imae.udg.edu>
Repository: CRAN
Date/Publication: 2025-04-20 21:30:02 UTC

coda.plot

Description

Easy to run function to built visualisations by means of 'ggplot2' objects.

Author(s)

Marc Comas-Cufí


Compositional Balance Dendrogram

Description

Plots a balance dendrogram based on a compositional data set and a corresponding balance matrix. This visualization helps interpret the structure of balances in compositional data analysis.

Usage

balance_dendrogram(X, B, group = NULL)

Arguments

X

A numeric matrix or data frame representing the compositional data. Rows are observations and columns are components (must be strictly positive).

B

A numeric matrix representing the balance basis (e.g., an isometric log-ratio (ilr) balance matrix).

group

Show boxplot by groups

Details

The dendrogram shows the hierarchical structure of balances derived from the balance matrix B. Each internal node corresponds to a balance, and the height or color may reflect the variance explained or other statistics.

Value

A 'ggplot2' object representing the balance dendrogram.

Examples

# Simulated compositional data and balances
X = matrix(runif(50, 1, 10), ncol = 5)
colnames(X) = LETTERS[1:5]
B = pb_basis(X, method = 'exact')
balance_dendrogram(X, B)


Compositional CLR Biplot

Description

Generates a centered log-ratio (CLR) biplot for compositional data.

Usage

clr_biplot(
  X,
  group = NULL,
  biplot_type = "covariance",
  alpha = NULL,
  shape_group = NULL
)

Arguments

X

A matrix or data frame containing compositional data.

group

factor used to color the observations.

biplot_type

Character string specifying the type of biplot. Either '"covariance"' (default) or '"form"'.

alpha

Optional numeric value between 0 and 1. If provided, this overrides biplot_type. Controls the type of biplot:

  • 0 = covariance biplot

  • 1 = form biplot

shape_group

Optional factor used to assign shapes to the observations.

Value

A ggplot object displaying the biplot.


Geometric Mean Barplot for Compositional Data

Description

Generates a barplot based on the geometric mean of compositional parts. Optionally, it can compare groups, display the parts on the x-axis, overlay boxplots, or use centered log-ratio (clr) transformation.

Usage

geometric_mean_barplot(
  X,
  group,
  x_show_parts = TRUE,
  include_boxplot = FALSE,
  clr_scale = FALSE
)

Arguments

X

A numeric matrix or data frame representing compositional data. Each row is an observation and each column is a part (must be strictly positive).

group

An optional factor or character vector indicating group membership for each observation.

x_show_parts

Logical. If TRUE, the x-axis displays parts instead of group labels. Default is TRUE.

include_boxplot

Logical. If TRUE, a boxplot is overlaid on top of the barplot. Default is FALSE.

clr_scale

Logical. If TRUE, the data are transformed to clr coordinates before computing geometric means. Default is FALSE.

Details

The function computes geometric means for each compositional part, optionally stratified by groups. If clr_scale = TRUE, the data are transformed using the centered log-ratio transformation before computing means. Overlaying a boxplot can help visualize within-group variability.

Value

A 'ggplot2' object representing the geometric mean barplot.

Examples

# Example with simulated compositional data
X = matrix(runif(30, 1, 10), ncol = 3)
colnames(X) = c("A", "B", "C")
group = rep(c("G1", "G2"), each = 5)
geometric_mean_barplot(X, group, include_boxplot = TRUE)


Ternary Diagram

Description

Generates a ternary diagram from compositional data, with options to center, scale, and color the points by group. Optionally overlays principal components.

Usage

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

Arguments

X

A numeric matrix or data frame of compositional data with exactly three columns.

group

A factor or character vector indicating groups for color coding (optional).

center

Logical. Should the data be centered before plotting? Default is FALSE.

scale

Logical. Should the data be scaled to unit variance? Default is FALSE.

show_pc

Logical. If TRUE, principal components are overlaid. Default is FALSE.

Value

A ggtern plot object (inherits from ggplot).

Examples

X = milk_cows[,5:7]
group = milk_cows$group
ternary_diagram(X, group = group)