taxa_contribution_bar: Stacked bar plot of taxa contributions

View source: R/taxa_contribution_viz.R

taxa_contribution_barR Documentation

Stacked bar plot of taxa contributions

Description

Creates a stacked bar plot showing taxa contributions to predicted functional abundances, faceted by function or sample group.

Usage

taxa_contribution_bar(
  contrib_agg,
  metadata,
  group,
  function_ids = NULL,
  n_functions = 6,
  facet_by = "function",
  show_percentage = TRUE,
  color_theme = "default",
  font_size = 12,
  legend_position = "right",
  custom_title = NULL
)

Arguments

contrib_agg

A data.frame from aggregate_taxa_contributions.

metadata

A data.frame containing sample metadata.

group

Character. Column name in metadata for grouping samples.

function_ids

Optional character vector of function IDs to plot. If NULL (default), the top n_functions by variance are shown.

n_functions

Integer. Number of functions to show when function_ids is NULL. Default 6.

facet_by

Character. Facet by "function" (default) or "group".

show_percentage

Logical. Normalize bars to 100%? Default TRUE.

color_theme

Character. Color theme name, passed to get_color_theme. Default "default".

font_size

Numeric. Base font size. Default 12.

legend_position

Character. Legend position. Default "right".

custom_title

Optional character string for the plot title.

Value

A ggplot2 object.

Examples


# Synthetic example
agg <- data.frame(
  sample = rep(c("S1", "S2", "S3", "S4"), each = 3),
  function_id = rep(c("K00001", "K00002"), each = 6),
  taxon_label = rep(c("Genus_A", "Genus_B", "Other"), 4),
  contribution = runif(12)
)
metadata <- data.frame(
  sample = c("S1", "S2", "S3", "S4"),
  group = c("Control", "Control", "Treatment", "Treatment")
)
p <- taxa_contribution_bar(agg, metadata, group = "group")



ggpicrust2 documentation built on April 10, 2026, 5:06 p.m.