Learn R Programming

coda.plot (version 0.1.9)

geometric_mean_barplot: 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
)

Value

A 'ggplot2' object representing the geometric mean barplot.

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab