
Generate Pairwise Taxa Barplots
Source:R/generate_taxa_barplot_pair.R
generate_taxa_barplot_pair.RdCreates stacked barplots comparing taxonomic composition between paired time points. Supports grouping and stratification with both individual and average views.
Usage
generate_taxa_barplot_pair(
data.obj,
subject.var,
time.var,
group.var = NULL,
strata.var = NULL,
feature.level,
feature.dat.type = c("count", "proportion", "other"),
feature.number = 20,
features.plot = NULL,
base.size = 10,
theme.choice = "bw",
custom.theme = NULL,
palette = NULL,
pdf = TRUE,
file.ann = NULL,
pdf.wid = 11,
pdf.hei = 8.5,
...
)Arguments
- data.obj
A MicrobiomeStat data object, which is a list containing at minimum the following components:
feature.tab: A matrix of feature abundances (taxa/genes as rows, samples as columns)meta.dat: A data frame of sample metadata (samples as rows)
Optional components include:
feature.ann: A matrix/data frame of feature annotations (e.g., taxonomy)tree: A phylogenetic tree object (class "phylo")feature.agg.list: Pre-aggregated feature tables by taxonomy
Data objects can be created using converters like
mStat_convert_phyloseq_to_data_objor importers likemStat_import_qiime2_as_data_obj.- subject.var
Character string specifying the column name in meta.dat that uniquely identifies each subject or sample unit. Required for longitudinal and paired designs to track repeated measurements.
- time.var
Character string specifying the column name in meta.dat containing the time variable. Required for longitudinal and paired analyses. Supports character/factor labels (e.g., "baseline", "week4") and numeric values. Some trend/volatility methods require numeric or coercible-to-numeric time values.
- group.var
Character string specifying the column name in meta.dat containing the grouping variable (e.g., treatment, condition, phenotype). Used for between-group comparisons.
- strata.var
Character string specifying the column name in meta.dat for stratification. When provided, analyses and visualizations will be performed separately within each stratum (e.g., by site, batch, or sex).
- feature.level
Character vector specifying the taxonomic or annotation level(s) for analysis. Should match column names in feature.ann, such as "Phylum", "Family", "Genus", etc. Use "original" to analyze at the original feature level without aggregation.
- feature.dat.type
Character string specifying the data type of feature.tab. One of:
"count": Raw count data (will be normalized)
"proportion": Relative abundance data (should sum to 1 per sample)
"other": Pre-transformed data (no transformation applied)
- feature.number
Integer specifying number of top features to display. Lower-ranked features are grouped into "Other". Default is 20.
- features.plot
Character vector of specific feature IDs to plot. If NULL, top features by mean abundance are displayed.
- base.size
Numeric value specifying the base font size for plot text elements. Default is typically 16.
- theme.choice
Character string specifying the ggplot2 theme to use. Options include:
"bw": Black and white theme (theme_bw)
"classic": Classic theme (theme_classic)
"gray": Gray theme (theme_gray)
"light": Light theme (theme_light)
"dark": Dark theme (theme_dark)
"minimal": Minimal theme (theme_minimal)
"void": Void theme (theme_void)
"prism": GraphPad Prism-like theme
Can also use a custom ggplot2 theme object via custom.theme.
- custom.theme
A custom ggplot2 theme object to override theme.choice. Should be created using ggplot2::theme() or a complete theme function.
- palette
Character vector of colors or a named palette for the plot. If NULL, uses default MicrobiomeStat color scheme. Can be:
A vector of color codes (e.g., c("#E41A1C", "#377EB8"))
A palette name recognized by the plotting function
Logical. If TRUE, saves the plot(s) to PDF file(s) in the current working directory. Default is TRUE.
- file.ann
Character string for additional annotation to append to output filenames. Useful for distinguishing multiple outputs.
- pdf.wid
Numeric value specifying the width of PDF output in inches. Default is typically 11.
- pdf.hei
Numeric value specifying the height of PDF output in inches. Default is typically 8.5.
- ...
Additional arguments passed to underlying functions.
Examples
if (FALSE) { # \dontrun{
data(peerj32.obj)
generate_taxa_barplot_pair(
data.obj = peerj32.obj,
subject.var = "subject",
time.var = "time",
group.var = "group",
strata.var = "sex",
feature.level = "Genus",
feature.dat.type = c("count"),
feature.number = 20,
base.size = 10,
theme.choice = "bw",
custom.theme = NULL,
palette = NULL,
pdf = TRUE,
file.ann = NULL,
pdf.wid = 25,
pdf.hei = 8.5
)
data(subset_pairs.obj)
generate_taxa_barplot_pair(
data.obj = subset_pairs.obj,
subject.var = "MouseID",
time.var = "Antibiotic",
group.var = "Sex",
strata.var = NULL,
feature.level = "Genus",
feature.dat.type = c("count"),
feature.number = 30,
base.size = 10,
theme.choice = "bw",
custom.theme = NULL,
palette = NULL,
pdf = TRUE,
file.ann = NULL,
pdf.wid = 11,
pdf.hei = 8.5
)
} # }