Learn R Programming

barrel (version 0.1.0)

barrel_stats: Comprehensive Ordination Visualization Layer

Description

Combines ordination ellipses, centroids, environmental arrows, and annotations into a ggplot2 layer.

Usage

stat_barrel(
  mapping = NULL,
  data = NULL,
  geom = "path",
  position = "identity",
  kind = "se",
  conf = 0.95,
  method = c("robust", "classic"),
  show.legend = NA,
  inherit.aes = TRUE,
  geom_type = c("path", "polygon"),
  ...
)

stat_barrel_centroid( mapping = NULL, data = NULL, geom = "point", position = "identity", method = c("classic", "robust"), show.legend = NA, inherit.aes = TRUE, shape = 3, ... )

stat_barrel_arrows( mapping = NULL, data = NULL, ord, matrix, geom = "segment", position = "identity", labels = TRUE, labels.color = "black", labels.size = 3, labels.fontface = "plain", show.significant = FALSE, p_thresh = 0.05, arrow = grid::arrow(length = grid::unit(0.25, "cm")), arrow.color = "grey10", arrow.linetype = "solid", arrow.size = 0.3, labels.max.overlaps = Inf, show.legend = NA, inherit.aes = TRUE, ... )

compute_envfit_vectors(ord, matrix, p_thresh = 0.05, show.significant = FALSE)

stat_barrel_annotate( mapping = NULL, data = NULL, ord, position = "identity", show.legend = FALSE, inherit.aes = TRUE, xpad = 0.05, ypad = 0.05, hjust = 0, vjust = 1, ... )

Value

A ggplot2 layer combining ellipses, centroids, arrows, and annotations.

Arguments

mapping

Set of aesthetic mappings created by aes().

data

Data frame used for plotting.

geom

Character; geometric object to use for ellipses, either "path" or "polygon".

position

Position adjustment for ggplot2 layers (default "identity").

kind

Character; type of ellipse: "se" (standard error), "sd" (dispersion), or "ci" (confidence interval).

conf

Numeric; confidence level for ellipses (default 0.95).

method

Character; covariance estimation method: "classic" or "robust".

show.legend

Logical; whether to show legends (default NA).

inherit.aes

Logical; whether to inherit aesthetics (default TRUE).

geom_type

Character; geometric object to use for ellipses, either "path" or "polygon".

...

Additional parameters passed to underlying geoms or stats.

shape

Integer; shape code for centroid points (default 3).

ord

Ordination object from vegan, e.g. rda, cca, dbrda, or metaMDS.

matrix

Optional data frame of environmental variables for arrows.

labels

Logical; whether to show labels on environmental arrows (default TRUE).

labels.color

Color of arrow labels (default "black").

labels.size

Numeric size of arrow labels (default 3).

labels.fontface

Font face of arrow labels (default "plain").

show.significant

Logical; whether to show only significant arrows (default FALSE).

p_thresh

Numeric; p-value threshold for significance filtering (default 0.05).

arrow

A grid arrow object controlling arrow appearance (default created by grid::arrow()).

arrow.color

Color of arrows (default "grey10").

arrow.linetype

Line type of arrows (default "solid").

arrow.size

Numeric line width of arrows (default 0.3).

labels.max.overlaps

Maximum number of labels in the same space (default "Inf").

xpad

Numeric; horizontal padding for annotation text relative to x-axis range (default 0.05).

ypad

Numeric; vertical padding for annotation text relative to y-axis range (default 0.05).

hjust

Numeric; horizontal justification of annotation text (default 0).

vjust

Numeric; vertical justification of annotation text (default 1).

Details

Comprehensive Ordination Visualization Layer

This set of ggplot2 stats draws ellipses around groups, centroids, environmental arrows, and adds adjusted R^2 or stress annotation for ordination objects from vegan.

Examples

Run this code
library(ggplot2)
library(vegan)
library(robustbase)
data(dune)
data(dune.env)

pca <- vegan::rda(dune, scale = TRUE)
scores <- as.data.frame(vegan::scores(pca, display = "sites"))
scores$Management <- dune.env$Management

ggplot(scores, aes(PC1, PC2, group = Management, fill = Management)) +
  stat_barrel(
    method = "classic", kind = "se", conf = 0.95, geom_type = "polygon",
    alpha = 0.4, color = "black"
  ) +
  stat_barrel_centroid(method = "classic", shape = 3) +
  stat_barrel_arrows(
    ord = pca, matrix = dune,
    labels = TRUE, labels.color = "blue",
    arrow.color = "darkred", arrow.linetype = "solid",
    labels.fontface = "bold", show.significant = TRUE,
    labels.max.overlaps = Inf,
  ) +
  stat_barrel_annotate(ord = pca, xpad = 0.05, ypad = 0.05) +
  geom_point(aes(color = Management)) +
  theme_minimal()

Run the code above in your browser using DataLab