geometric_mean_barplot {coda.plot} | R Documentation |
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 |
include_boxplot |
Logical. If |
clr_scale |
Logical. If |
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)