View source: R/taxa_contribution_viz.R
| taxa_contribution_bar | R Documentation |
Creates a stacked bar plot showing taxa contributions to predicted functional abundances, faceted by function or sample group.
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
)
contrib_agg |
A data.frame from |
metadata |
A data.frame containing sample metadata. |
group |
Character. Column name in |
function_ids |
Optional character vector of function IDs to plot.
If NULL (default), the top |
n_functions |
Integer. Number of functions to show when
|
facet_by |
Character. Facet by |
show_percentage |
Logical. Normalize bars to 100%? Default TRUE. |
color_theme |
Character. Color theme name, passed to
|
font_size |
Numeric. Base font size. Default 12. |
legend_position |
Character. Legend position. Default |
custom_title |
Optional character string for the plot title. |
The sample, function_id, and taxon_label columns must
contain non-empty values without NA. These columns define plotting and
aggregation groups, so missing identifiers would otherwise be dropped by R
aggregation or shown as unlabeled categories.
When show_percentage = TRUE, every plotted sample/function
combination must have a positive total contribution. Relative percentages
are undefined for zero-total combinations; use show_percentage = FALSE
to display absolute zero contributions.
A ggplot2 object.
# Synthetic example
agg <- expand.grid(
sample = c("S1", "S2", "S3", "S4"),
function_id = c("K00001", "K00002"),
taxon_label = c("Genus_A", "Genus_B", "Other"),
stringsAsFactors = FALSE
)
agg$contribution <- runif(nrow(agg))
metadata <- data.frame(
sample = c("S1", "S2", "S3", "S4"),
group = c("Control", "Control", "Treatment", "Treatment")
)
p <- taxa_contribution_bar(agg, metadata, group = "group")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.