| Title: | Analysis and Visualization of Microbiome Diversity, Composition, and Differential Abundance |
|---|---|
| Description: | The goal of MicroBioMeta is to support beginners in microbiome data analysis, whether working with metagenomic or metabarcoding datasets. It enables users with limited experience in R to explore, visualize, and analyze results with minimal coding and customization. This helps save time on scripting, while still producing statistically robust results and publication-ready figures in an intuitive and accessible way. |
| Authors: | Stephanie Hereira Pacheco [aut, cre] (ORCID: <https://orcid.org/0000-0003-1433-8187>), Nina Montoya Ciriaco [aut] (ORCID: <https://orcid.org/0009-0000-3555-0692>), Karla Zarco González [aut] (ORCID: <https://orcid.org/0009-0003-3407-9036>) |
| Maintainer: | Stephanie Hereira Pacheco <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 0.99.0 |
| Built: | 2026-11-20 23:03:21 UTC |
| Source: | https://github.com/BiocStaging/MicroBioMeta |
Generates a bar plot of relative abundance (%) for the most abundant taxa groups across samples or sample groups.
abundance_bar_plot( table, metadata = NULL, taxonomy_db = "silva", level = "genus", x_col = NULL, facet_by = NULL, width_equal = FALSE, label = "taxonomy", top_n = 15, x_axis_title = "Samples", y_axis_title = "Relative abundance (%)", x_label_angle = 0, strip_text_bold = FALSE, strip_color = "grey", palette = "default", taxa_colors = NULL, taxa_order = "ascending", aspect_ratio = NULL, add_remained = FALSE, save_table = FALSE, table_filename = "relative_abundance.txt" )abundance_bar_plot( table, metadata = NULL, taxonomy_db = "silva", level = "genus", x_col = NULL, facet_by = NULL, width_equal = FALSE, label = "taxonomy", top_n = 15, x_axis_title = "Samples", y_axis_title = "Relative abundance (%)", x_label_angle = 0, strip_text_bold = FALSE, strip_color = "grey", palette = "default", taxa_colors = NULL, taxa_order = "ascending", aspect_ratio = NULL, add_remained = FALSE, save_table = FALSE, table_filename = "relative_abundance.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
taxonomy_db |
Character. Database the taxonomy strings come from:
|
level |
Character. Taxonomic level: |
x_col |
Character. Name of the column in |
facet_by |
Character. Name of the column in |
width_equal |
Logical. If |
label |
Character. Title of the taxa legend. Default |
top_n |
Integer. Number of most abundant taxa to show. Default
|
x_axis_title |
Character. Title of the x-axis. Default
|
y_axis_title |
Character. Title of the y-axis. Default |
x_label_angle |
Numeric. Rotation (degrees) of the x-axis labels.
Default |
strip_text_bold |
Logical. If |
strip_color |
Character. Background color of the facet strips (used
when |
palette |
Character. Palette for the taxa: |
taxa_colors |
Optional named character vector of colors, one per taxon
(names = taxa as shown in the legend). Taxa not named keep the
|
taxa_order |
Character. Order of the taxa in the bars and the legend:
|
aspect_ratio |
Numeric. Aspect ratio (height/width) of each panel.
Default |
add_remained |
Logical. If |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
Relative abundances are calculated per sample (%).
Taxa are collapsed to the taxonomic level; taxa not resolved to that level are shown as "other
Only the top top_n taxa are shown; others are filtered out.
Samples are grouped and ordered according to x_col.
Optional faceting by facet_by if provided.
Features assigned only to a kingdom/domain (e.g. "d__Bacteria;__;__;__;__;__") or "Unassigned" are removed.
A ggplot object with the stacked bar plot of relative abundances.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) abundance_bar_plot( table = table, metadata = metadata, taxonomy_db = "silva", level = "genus", x_col = "Location", label = "Genus", facet_by = "Treatment", top_n = 30, add_remained = TRUE )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) abundance_bar_plot( table = table, metadata = metadata, taxonomy_db = "silva", level = "genus", x_col = "Location", label = "Genus", facet_by = "Treatment", top_n = 30, add_remained = TRUE )
Creates a heatmap (with ComplexHeatmap) of the relative abundance of the most abundant features (ASVs, OTUs or taxa).
abundance_heatmap_plot( table, metadata = NULL, condition1 = NULL, condition2 = NULL, condition3 = NULL, colors_condition1 = NULL, colors_condition2 = NULL, colors_condition3 = NULL, name_legend_condition1 = NULL, name_legend_condition2 = NULL, name_legend_condition3 = NULL, top_n = 15, exclude_unclassified = TRUE, cluster = TRUE, show_column_names = TRUE, cell_size = NULL, annotation_height = NULL, save_table = FALSE, table_filename = "abundance_heatmap_table.txt", feature_prefix = "", max_label_length = 35, composite_names = TRUE, draw = TRUE )abundance_heatmap_plot( table, metadata = NULL, condition1 = NULL, condition2 = NULL, condition3 = NULL, colors_condition1 = NULL, colors_condition2 = NULL, colors_condition3 = NULL, name_legend_condition1 = NULL, name_legend_condition2 = NULL, name_legend_condition3 = NULL, top_n = 15, exclude_unclassified = TRUE, cluster = TRUE, show_column_names = TRUE, cell_size = NULL, annotation_height = NULL, save_table = FALSE, table_filename = "abundance_heatmap_table.txt", feature_prefix = "", max_label_length = 35, composite_names = TRUE, draw = TRUE )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
condition1 |
Character. Name of the column in |
condition2 |
Character. Name of the column in |
condition3 |
Character. Name of the column in |
colors_condition1 |
Optional character vector of colors for
|
colors_condition2 |
Optional character vector of colors for
|
colors_condition3 |
Optional character vector of colors for
|
name_legend_condition1 |
Character. Title of the legend of
|
name_legend_condition2 |
Character. Title of the legend of
|
name_legend_condition3 |
Character. Title of the legend of
|
top_n |
Integer. Number of most abundant features to show. Default
|
exclude_unclassified |
Logical. If |
cluster |
Logical. If |
show_column_names |
Logical. If |
cell_size |
Numeric. Side, in millimeters, of each (square) cell. If
|
annotation_height |
Numeric. Height, in millimeters, of each column
annotation bar ( |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
feature_prefix |
Character. Prefix of the row labels, before the row
number (e.g. |
max_label_length |
Integer. Taxon names longer than this many
characters are cut with an ellipsis in the row labels. |
composite_names |
Logical. If |
draw |
Logical. If |
Invisibly, a gTree (grid grob) with the heatmap of the
top_n most abundant features. Printing it (e.g. typing its name)
draws the heatmap; it can also be combined with other plots (e.g.
cowplot::plot_grid(), patchwork::wrap_elements()).
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) abundance_heatmap_plot( table = table, metadata = metadata, condition1 = "Location", condition2 = "Treatment", condition3 = "Plot", top_n = 50, cluster = TRUE, show_column_names = FALSE, name_legend_condition1 = "Location", name_legend_condition2 = "Treatment", name_legend_condition3 = "Plot" ) heat <- abundance_heatmap_plot( table = table, metadata = metadata, condition1 = "Location", condition2 = "Treatment", top_n = 20, show_column_names = FALSE, colors_condition1 = c(Rhizosphere = "#56B4E9", Roots = "#009E73"), colors_condition2 = c( Control = "#CC6677", Moderate_drought = "#332288", Severe_drought = "#999933" ), name_legend_condition1 = "Compartment", feature_prefix = "ASV", max_label_length = 30, draw = FALSE ) heat # printing the returned object draws the heatmaptable_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) abundance_heatmap_plot( table = table, metadata = metadata, condition1 = "Location", condition2 = "Treatment", condition3 = "Plot", top_n = 50, cluster = TRUE, show_column_names = FALSE, name_legend_condition1 = "Location", name_legend_condition2 = "Treatment", name_legend_condition3 = "Plot" ) heat <- abundance_heatmap_plot( table = table, metadata = metadata, condition1 = "Location", condition2 = "Treatment", top_n = 20, show_column_names = FALSE, colors_condition1 = c(Rhizosphere = "#56B4E9", Roots = "#009E73"), colors_condition2 = c( Control = "#CC6677", Moderate_drought = "#332288", Severe_drought = "#999933" ), name_legend_condition1 = "Compartment", feature_prefix = "ASV", max_label_length = 30, draw = FALSE ) heat # printing the returned object draws the heatmap
Creates an interactive Sankey diagram (with networkD3) of how the relative abundance flows across taxonomic ranks.
abundance_sankey_plot( table, output_file = NULL, maxn = 25, taxRanks = c("D", "K", "P", "C", "O", "F", "G", "S"), taxonomy_db = "silva", width = NULL, height = NULL, save_table = FALSE, table_filename = "sankey_nodes_links.txt" )abundance_sankey_plot( table, output_file = NULL, maxn = 25, taxRanks = c("D", "K", "P", "C", "O", "F", "G", "S"), taxonomy_db = "silva", width = NULL, height = NULL, save_table = FALSE, table_filename = "sankey_nodes_links.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
output_file |
Character or |
maxn |
Integer. Maximum number of taxa per rank. Default |
taxRanks |
Character vector of the ranks to show, as one-letter codes:
|
taxonomy_db |
Character. Database the taxonomy strings come from:
|
width, height
|
Numeric or |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
Invisibly returns the Sankey diagram object (an htmlwidget that
is shown when printed). If output_file is given, it is also saved
as an HTML file.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) abundance_sankey_plot( table = table, output_file = file.path(tempdir(), "sankey_output.html"), maxn = 10, taxRanks = c("P", "C", "G", "S"), taxonomy_db = "silva" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) abundance_sankey_plot( table = table, output_file = file.path(tempdir(), "sankey_output.html"), maxn = 10, taxRanks = c("P", "C", "G", "S"), taxonomy_db = "silva" )
Runs ALDEx2 between two groups and shows the differentially abundant taxa as a heatmap (with ComplexHeatmap) of their CLR values, annotated with the effect size and the p-value.
aldex_heatmap_plot( table, metadata, group_col, effect_threshold = 0, pval_threshold = 0.05, p_adjust_method = "BH", mc_samples = 128, cluster_rows = FALSE, cluster_columns = FALSE, heatmap_colors = NULL, effect_colors = c("#009E73", "white", "#CC79A7"), pvalue_colors = c(`<0.001` = "#000000", `<0.01` = "#D55E00", `<0.05` = "#F0E442", `>0.05` = "grey85"), group_colors = NULL, save_table = FALSE, table_filename = "aldex_pval_effect.txt", draw = TRUE )aldex_heatmap_plot( table, metadata, group_col, effect_threshold = 0, pval_threshold = 0.05, p_adjust_method = "BH", mc_samples = 128, cluster_rows = FALSE, cluster_columns = FALSE, heatmap_colors = NULL, effect_colors = c("#009E73", "white", "#CC79A7"), pvalue_colors = c(`<0.001` = "#000000", `<0.01` = "#D55E00", `<0.05` = "#F0E442", `>0.05` = "grey85"), group_colors = NULL, save_table = FALSE, table_filename = "aldex_pval_effect.txt", draw = TRUE )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
group_col |
Character. Name of the column in |
effect_threshold |
Numeric. Minimum absolute effect size to retain.
Default |
pval_threshold |
Numeric or |
p_adjust_method |
Character. |
mc_samples |
Integer. Number of ALDEx2 Monte Carlo instances. Default
|
cluster_rows |
Logical. Cluster heatmap rows (default |
cluster_columns |
Logical. Cluster heatmap columns (default |
heatmap_colors |
Controls the color scale of the main heatmap body (CLR values).
Three options: |
effect_colors |
Three colors for the effect size annotation strip:
negative, zero and positive effect (mapped to -1.5, 0 and 1.5). Default
|
pvalue_colors |
Named vector of colors for the p-value annotation
strip, with names |
group_colors |
Optional character vector of colors for the group
annotation, one per group, named after the groups or in their order. If
|
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
draw |
Logical. If |
Invisibly, a gTree (grid grob) with the heatmap. Printing it
(e.g. typing its name) draws the heatmap; it can also be combined with
other plots (e.g. cowplot::plot_grid(),
patchwork::wrap_elements()).
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # group_col must have exactly two groups; Location has two # (Rhizosphere and Roots) in the bundled example data. Here taxa are # filtered by effect size alone (pval_threshold = NULL), since this small # (46-sample) dataset has few taxa with significant p-values. aldex_heatmap_plot( table = table, metadata = metadata, group_col = "Location", mc_samples = 16, effect_threshold = 0.5, pval_threshold = NULL ) # All the colors have colorblind-friendly defaults, but each can be set by # hand: group_colors (difference bars, named after the groups), # effect_colors (negative, zero and positive effect size), pvalue_colors # (one color per p-value class) and heatmap_colors (median clr values) aldex_heatmap_plot( table = table, metadata = metadata, group_col = "Location", mc_samples = 16, effect_threshold = 0.5, pval_threshold = NULL, group_colors = c(Rhizosphere = "#56B4E9", Roots = "#009E73"), effect_colors = c("#0072B2", "white", "#E69F00"), pvalue_colors = c( "<0.001" = "black", "<0.01" = "grey30", "<0.05" = "grey60", ">0.05" = "grey90" ), heatmap_colors = "BuOr" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # group_col must have exactly two groups; Location has two # (Rhizosphere and Roots) in the bundled example data. Here taxa are # filtered by effect size alone (pval_threshold = NULL), since this small # (46-sample) dataset has few taxa with significant p-values. aldex_heatmap_plot( table = table, metadata = metadata, group_col = "Location", mc_samples = 16, effect_threshold = 0.5, pval_threshold = NULL ) # All the colors have colorblind-friendly defaults, but each can be set by # hand: group_colors (difference bars, named after the groups), # effect_colors (negative, zero and positive effect size), pvalue_colors # (one color per p-value class) and heatmap_colors (median clr values) aldex_heatmap_plot( table = table, metadata = metadata, group_col = "Location", mc_samples = 16, effect_threshold = 0.5, pval_threshold = NULL, group_colors = c(Rhizosphere = "#56B4E9", Roots = "#009E73"), effect_colors = c("#0072B2", "white", "#E69F00"), pvalue_colors = c( "<0.001" = "black", "<0.01" = "grey30", "<0.05" = "grey60", ">0.05" = "grey90" ), heatmap_colors = "BuOr" )
Runs ALDEx2 between two groups and plots the results as a volcano plot or an effect size plot.
aldex_volcano_plot( table, metadata, group_col, type = "volcano", mc_samples = 128, col_inf = "#56B4E9", col_sup = "#E69F00", threshold_lower = -1.5, threshold_upper = 1.5, cond = NULL, pval_threshold = 0.05, p_adjust_method = "BH", show_labels = TRUE, taxa = NULL, x_axis_title = NULL, y_axis_title = NULL, label_size = 3.5, filter_uncultured = FALSE, save_table = FALSE, table_filename = "aldex_pval_effect.txt" )aldex_volcano_plot( table, metadata, group_col, type = "volcano", mc_samples = 128, col_inf = "#56B4E9", col_sup = "#E69F00", threshold_lower = -1.5, threshold_upper = 1.5, cond = NULL, pval_threshold = 0.05, p_adjust_method = "BH", show_labels = TRUE, taxa = NULL, x_axis_title = NULL, y_axis_title = NULL, label_size = 3.5, filter_uncultured = FALSE, save_table = FALSE, table_filename = "aldex_pval_effect.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
group_col |
Character. Name of the column in |
type |
Type of plot to generate: |
mc_samples |
Integer. Number of ALDEx2 Monte Carlo instances. Default
|
col_inf |
Character. Color of the taxa lower in |
col_sup |
Character. Color of the taxa higher in |
threshold_lower |
Numeric. Lower cutoff on the x-axis (effect size or
difference between groups), drawn as a dashed line. Default |
threshold_upper |
Numeric. Upper cutoff on the x-axis (effect size or
difference between groups), drawn as a dashed line. Default |
cond |
Name of the reference condition for the plot labels: positive
values on the x-axis mean higher in |
pval_threshold |
Numeric. P-value cutoff (after
|
p_adjust_method |
Character. |
show_labels |
Logical. If |
taxa |
Optional data frame with columns |
x_axis_title, y_axis_title
|
Titles for the x- and y-axis. Default
|
label_size |
Numeric. Font size of the taxon labels drawn on
significant points in the "volcano" plot. Default |
filter_uncultured |
Logical. If |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A ggplot object with the selected plot.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # group_col must have exactly two groups; Location has two # (Rhizosphere and Roots) in the bundled example data aldex_volcano_plot( table = table, metadata = metadata, group_col = "Location", mc_samples = 16, type = "effect", col_inf = "#56B4E9", col_sup = "#E69F00", threshold_lower = -0.5, threshold_upper = 0.5, cond = "Rhizosphere", show_labels = TRUE )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # group_col must have exactly two groups; Location has two # (Rhizosphere and Roots) in the bundled example data aldex_volcano_plot( table = table, metadata = metadata, group_col = "Location", mc_samples = 16, type = "effect", col_inf = "#56B4E9", col_sup = "#E69F00", threshold_lower = -0.5, threshold_upper = 0.5, cond = "Rhizosphere", show_labels = TRUE )
Computes Hill numbers (q = 0, 1, 2) from table and plots them
against a continuous metadata variable (e.g. distance to urban center,
elevation, pH). It reports the Spearman rank correlation coefficient (rho, or Pearson r),
its p-value, and optionally the linear regression and slope.
alpha_decay_plot( table, metadata, cont_var, group_col = NULL, method = "spearman", show_lm_stats = TRUE, facet_orientation = "horizontal", palette = "colorb", group_colors = NULL, x_axis_title = NULL, y_axis_title = "Effective number of features", title = NULL, show_legend = TRUE, legend_position = "bottom", free_y = TRUE, point_size = 2, line_width = 0.9, point_alpha = 0.8, annotation_size = 3.5, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, strip_text_bold = FALSE )alpha_decay_plot( table, metadata, cont_var, group_col = NULL, method = "spearman", show_lm_stats = TRUE, facet_orientation = "horizontal", palette = "colorb", group_colors = NULL, x_axis_title = NULL, y_axis_title = "Effective number of features", title = NULL, show_legend = TRUE, legend_position = "bottom", free_y = TRUE, point_size = 2, line_width = 0.9, point_alpha = 0.8, annotation_size = 3.5, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, strip_text_bold = FALSE )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
cont_var |
Character. Name of the continuous variable column in
|
group_col |
Character. Name of the column in |
method |
Character. Correlation method for the statistic annotation.
One of |
show_lm_stats |
Logical. If |
facet_orientation |
Character. |
palette |
Character. Palette name: |
group_colors |
Optional character vector of colors, one per group,
named after the groups or in their order. Overrides |
x_axis_title |
Character. Title of the x-axis. If |
y_axis_title |
Character. Title of the y-axis. Default |
title |
Character. Plot title. |
show_legend |
Logical. If |
legend_position |
Character. Position of the legend: |
free_y |
Logical. If |
point_size |
Numeric. Size of the points. Default |
line_width |
Numeric. Width of regression lines. Default |
point_alpha |
Numeric (0-1). Transparency of the points. Default
|
annotation_size |
Numeric. Font size for the stats annotation.
Default |
panel_label_case |
Character. Case of the panel tags: |
panel_labels |
Optional character vector of custom panel tags, one per
panel (q0, q1, q2), used as-is (e.g. |
panel_label_bold |
Logical. If |
strip_text_bold |
Logical. If |
A patchwork object with the three q0/q1/q2 panels, tagged as
set by panel_label_case or panel_labels. It can still be
modified: p & theme(...) changes every panel, p[[2]] +
labs(...) a single one.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) loc_dist <- data.frame(Loc = 1:7, dist_km = seq(0, 12, length.out = 7)) metadata$dist_km <- loc_dist$dist_km[match(metadata$Loc, loc_dist$Loc)] + stats::rnorm(nrow(metadata), sd = 0.3) # All samples, no grouping. Always tagged A/B/C (see panel_label_case and # panel_labels to customize) alpha_decay_plot( table = table, metadata = metadata, cont_var = "dist_km", x_axis_title = "Distance (km)" ) # Separate regression lines by location alpha_decay_plot( table = table, metadata = metadata, cont_var = "dist_km", x_axis_title = "Distance (km)", group_col = "Location" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) loc_dist <- data.frame(Loc = 1:7, dist_km = seq(0, 12, length.out = 7)) metadata$dist_km <- loc_dist$dist_km[match(metadata$Loc, loc_dist$Loc)] + stats::rnorm(nrow(metadata), sd = 0.3) # All samples, no grouping. Always tagged A/B/C (see panel_label_case and # panel_labels to customize) alpha_decay_plot( table = table, metadata = metadata, cont_var = "dist_km", x_axis_title = "Distance (km)" ) # Separate regression lines by location alpha_decay_plot( table = table, metadata = metadata, cont_var = "dist_km", x_axis_title = "Distance (km)", group_col = "Location" )
Computes the Chao1, Shannon and Simpson indices of each sample (or Faith's
phylogenetic diversity or Rao's quadratic entropy, see diversity) and
plots them as box plots or bar plots, one panel per index, optionally faceted
by one or two metadata variables and with statistical comparisons between
groups.
alpha_diversity_plot( table, metadata, type = "boxplot", stat = NULL, p_adjust_method = "holm", x_col, fill_col, facet_by = NULL, facet_by2 = NULL, facet_orientation = "horizontal", palette = "colorb", group_colors = NULL, n_cols = NULL, n_rows = NULL, strip_color = "grey", show_legend = TRUE, title = NULL, legend_title = NULL, legend_position = "bottom", x_axis_title = NULL, y_axis_title = NULL, free_y = FALSE, rarefy_depth = NULL, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, x_label_angle = 0, strip_text_bold = FALSE, aspect_ratio = NULL, save_table = FALSE, table_filename = "diversity.txt", diversity = "taxonomic", tree = NULL, traits = NULL )alpha_diversity_plot( table, metadata, type = "boxplot", stat = NULL, p_adjust_method = "holm", x_col, fill_col, facet_by = NULL, facet_by2 = NULL, facet_orientation = "horizontal", palette = "colorb", group_colors = NULL, n_cols = NULL, n_rows = NULL, strip_color = "grey", show_legend = TRUE, title = NULL, legend_title = NULL, legend_position = "bottom", x_axis_title = NULL, y_axis_title = NULL, free_y = FALSE, rarefy_depth = NULL, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, x_label_angle = 0, strip_text_bold = FALSE, aspect_ratio = NULL, save_table = FALSE, table_filename = "diversity.txt", diversity = "taxonomic", tree = NULL, traits = NULL )
table |
A data frame with taxa in rows and samples in columns. The last
column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
type |
Type of plot: |
stat |
Character or |
p_adjust_method |
Character. Multiple-testing correction for the
pairwise tests ( |
x_col |
Character. Name of the column in |
fill_col |
Character. Name of the column in |
facet_by |
Character. Name of the column in |
facet_by2 |
Character. Name of a second column in |
facet_orientation |
Character. |
palette |
Character. Palette name: |
group_colors |
Optional character vector of colors, one per group,
named after the groups or in their order. Overrides |
n_cols |
Integer. Number of columns of the facet grid. If |
n_rows |
Integer. Number of rows of the facet grid. If |
strip_color |
Character. Background color of the facet strips (used
when |
show_legend |
Logical. If |
title |
Character. Plot title. |
legend_title |
Character. Title of the legend. If |
legend_position |
Character. Position of the legend: |
x_axis_title |
Character. Title of the x-axis. Default |
y_axis_title |
Character. Title of the y-axis. Default |
free_y |
Logical. Each index always has its own y-axis scale (Chao1,
Shannon and Simpson have very different ranges). If |
rarefy_depth |
Integer. If given, the samples are rarefied to this
depth ( |
panel_label_case |
Character. Case of the panel tags (added to every
panel): |
panel_labels |
Optional character vector of custom panel tags, one per
panel, used as-is (e.g. |
panel_label_bold |
Logical. If |
x_label_angle |
Numeric. Rotation (degrees) of the x-axis labels.
Default |
strip_text_bold |
Logical. If |
aspect_ratio |
Numeric. Aspect ratio (height/width) of each panel.
Default |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
diversity |
Character. |
tree |
A rooted |
traits |
A data frame with taxa in rows and traits in columns. Used when
|
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # Panel tags (A/B/C) are always added (see panel_label_case and # panel_labels to customize their case/format); stat additionally # overlays p-value annotations on each panel alpha_diversity_plot( table = table, metadata = metadata, type = "barplot", x_col = "Location", fill_col = "Location", facet_by = "Treatment", free_y = TRUE, legend_position = "top", stat = "t.test", panel_label_case = "upper" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # Panel tags (A/B/C) are always added (see panel_label_case and # panel_labels to customize their case/format); stat additionally # overlays p-value annotations on each panel alpha_diversity_plot( table = table, metadata = metadata, type = "barplot", x_col = "Location", fill_col = "Location", facet_by = "Treatment", free_y = TRUE, legend_position = "top", stat = "t.test", panel_label_case = "upper" )
Computes the Hill numbers (q = 0, 1, 2) of each sample and plots each against the sequencing depth (total reads), with a regression line and the correlation coefficient, combining the three panels in one figure.
alpha_hill_corr_plot( table, method = "spearman", facet_orientation = "horizontal", title = "auto", panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, save_table = FALSE, table_filename = "hill.txt", x_axis_title = "Sequencing depth (number of reads)" )alpha_hill_corr_plot( table, method = "spearman", facet_orientation = "horizontal", title = "auto", panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, save_table = FALSE, table_filename = "hill.txt", x_axis_title = "Sequencing depth (number of reads)" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
method |
Character. Correlation method passed to
|
facet_orientation |
Character. |
title |
Character. Plot title. |
panel_label_case |
Character. Case of the panel tags: |
panel_labels |
Optional character vector of custom panel tags, one per
panel (q0, q1, q2), used as-is (e.g. |
panel_label_bold |
Logical. If |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
x_axis_title |
Character. Title of the x-axis of the three panels.
Default |
A patchwork object with the three q0/q1/q2 panels.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) # Always tagged A/B/C (see panel_label_case and panel_labels to customize) alpha_hill_corr_plot( table = table, facet_orientation = "horizontal" ) ## Using Pearson correlation instead of the default Spearman alpha_hill_corr_plot( table = table, method = "pearson" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) # Always tagged A/B/C (see panel_label_case and panel_labels to customize) alpha_hill_corr_plot( table = table, facet_orientation = "horizontal" ) ## Using Pearson correlation instead of the default Spearman alpha_hill_corr_plot( table = table, method = "pearson" )
Computes the Hill numbers (q = 0, 1, 2) of each sample and plots them as box plots or bar plots, one panel per order q, optionally faceted by one or two metadata variables and with statistical comparisons between groups.
alpha_hill_plot( table, metadata, type = "boxplot", stat = NULL, p_adjust_method = "holm", x_col, fill_col, facet_by = NULL, facet_by2 = NULL, facet_orientation = "horizontal", palette = "colorb", group_colors = NULL, n_cols = NULL, n_rows = NULL, strip_color = "grey", show_legend = TRUE, title = NULL, legend_title = NULL, legend_position = "bottom", x_axis_title = NULL, y_axis_title = NULL, free_y = FALSE, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, x_label_angle = 0, strip_text_bold = FALSE, aspect_ratio = NULL, save_table = FALSE, table_filename = "hill.txt", diversity = "taxonomic", tree = NULL, traits = NULL, tau = NULL )alpha_hill_plot( table, metadata, type = "boxplot", stat = NULL, p_adjust_method = "holm", x_col, fill_col, facet_by = NULL, facet_by2 = NULL, facet_orientation = "horizontal", palette = "colorb", group_colors = NULL, n_cols = NULL, n_rows = NULL, strip_color = "grey", show_legend = TRUE, title = NULL, legend_title = NULL, legend_position = "bottom", x_axis_title = NULL, y_axis_title = NULL, free_y = FALSE, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, x_label_angle = 0, strip_text_bold = FALSE, aspect_ratio = NULL, save_table = FALSE, table_filename = "hill.txt", diversity = "taxonomic", tree = NULL, traits = NULL, tau = NULL )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
type |
Type of plot: |
stat |
Character or |
p_adjust_method |
Character. Multiple-testing correction for the
pairwise tests ( |
x_col |
Character. Name of the column in |
fill_col |
Character. Name of the column in |
facet_by |
Character. Name of the column in |
facet_by2 |
Character. Name of a second column in |
facet_orientation |
Character. |
palette |
Character. Palette name: |
group_colors |
Optional character vector of colors, one per group,
named after the groups or in their order. Overrides |
n_cols |
Integer. Number of columns of the facet grid. If |
n_rows |
Integer. Number of rows of the facet grid. If |
strip_color |
Character. Background color of the facet strips (used
when |
show_legend |
Logical. If |
title |
Character. Plot title. |
legend_title |
Character. Title of the legend. If |
legend_position |
Character. Position of the legend: |
x_axis_title |
Character. Title of the x-axis. Default |
y_axis_title |
Character. Title of the y-axis. Default |
free_y |
Logical. Each order q always has its own y-axis scale (q0
is usually much larger than q2). If |
panel_label_case |
Character. Case of the panel tags (added to every
panel): |
panel_labels |
Optional character vector of custom panel tags, one per
panel, used as-is (e.g. |
panel_label_bold |
Logical. If |
x_label_angle |
Numeric. Rotation (degrees) of the x-axis labels.
Default |
strip_text_bold |
Logical. If |
aspect_ratio |
Numeric. Aspect ratio (height/width) of each panel.
Default |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
diversity |
Character.
|
tree |
A rooted |
traits |
A data frame with taxa in rows and traits in columns (e.g. the
EC or KO copy numbers predicted per ASV by PICRUSt2), converted to Gower
distances with |
tau |
Numeric. Threshold of functional distinctiveness: taxa at this
distance or more count as different functional groups. |
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # Panel tags (A/B/C) are always added (see panel_label_case and # panel_labels to customize their case/format); stat additionally # overlays p-value annotations on each panel alpha_hill_plot( table = table, metadata = metadata, type = "boxplot", x_col = "Location", fill_col = "Location", facet_by = "Treatment", legend_position = "top", stat = "kruskal.test", panel_label_case = "upper" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # Panel tags (A/B/C) are always added (see panel_label_case and # panel_labels to customize their case/format); stat additionally # overlays p-value annotations on each panel alpha_hill_plot( table = table, metadata = metadata, type = "boxplot", x_col = "Location", fill_col = "Location", facet_by = "Treatment", legend_position = "top", stat = "kruskal.test", panel_label_case = "upper" )
Runs ANCOMBC2 on a table and metadata, then visualizes differentially abundant taxa.
ancombc_plot( table, metadata, group_col, level = "genus", min_prevalence = 0.1, p_adjust_method = "holm", formula = NULL, rand_formula = NULL, ref_level = NULL, diverging_palette = "BuOr", x_axis_title = NULL, y_axis_title = NULL, bar_colors = c("#56B4E9", "#E69F00"), save_table = FALSE, table_filename = "ancombc_results.txt" )ancombc_plot( table, metadata, group_col, level = "genus", min_prevalence = 0.1, p_adjust_method = "holm", formula = NULL, rand_formula = NULL, ref_level = NULL, diverging_palette = "BuOr", x_axis_title = NULL, y_axis_title = NULL, bar_colors = c("#56B4E9", "#E69F00"), save_table = FALSE, table_filename = "ancombc_results.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
group_col |
Character. Name of the column in |
level |
Character or |
min_prevalence |
Numeric. Prevalence cut-off passed to |
p_adjust_method |
Character. Multiple-testing correction for the
ANCOMBC2 p-values of the taxa (passed to |
formula |
Character. Right-hand side of the fixed-effects formula
passed to |
rand_formula |
Character. Random-effects formula passed to
|
ref_level |
Character. Reference level of |
diverging_palette |
Character. Colorblind-friendly diverging palette of
the heatmap (3 or more groups): |
x_axis_title, y_axis_title
|
Titles for the x- and y-axis. Default
|
bar_colors |
Character vector of two colors for the bar plot: the first
for the taxa higher in the non-reference group, the second for those higher
in the reference group. Default |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A ggplot object: a bar plot (2 groups) or a heatmap (3 or more groups).
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) ancombc_plot( table = table, metadata = metadata, group_col = "Location", min_prevalence = 0.3, p_adjust_method = "BH" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) ancombc_plot( table = table, metadata = metadata, group_col = "Location", min_prevalence = 0.3, p_adjust_method = "BH" )
Computes the pairwise community dissimilarity (Jaccard, Morisita-Horn, Bray-Curtis or another vegdist method) and the pairwise geographic distance from the sample coordinates in metadata, and tests their relationship with a Mantel test.
beta_decay_plot( table, metadata, lat_col, lon_col, group_col = NULL, palette = "colorb", distance = "jaccard", method = "spearman", permutations = 999, show_lm_stats = TRUE, point_color = "black", line_color = "#D55E00", point_size = 1, point_alpha = 0.5, annotation_size = 3.5, x_axis_title = "Spatial distance (km)", y_axis_title = NULL, title = NULL )beta_decay_plot( table, metadata, lat_col, lon_col, group_col = NULL, palette = "colorb", distance = "jaccard", method = "spearman", permutations = 999, show_lm_stats = TRUE, point_color = "black", line_color = "#D55E00", point_size = 1, point_alpha = 0.5, annotation_size = 3.5, x_axis_title = "Spatial distance (km)", y_axis_title = NULL, title = NULL )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
lat_col |
Character. Name of the latitude column in |
lon_col |
Character. Name of the longitude column in |
group_col |
Character. Name of the column in |
palette |
Palette name ( |
distance |
Character. Dissimilarity metric passed to
|
method |
Character. Correlation method for the Mantel test:
|
permutations |
Integer. Number of permutations for the Mantel test.
Default |
show_lm_stats |
Logical. If |
point_color |
Character. Color of scatter points. Default
|
line_color |
Character. Color of the regression line. Default
|
point_size |
Numeric. Size of the points. Default |
point_alpha |
Numeric (0-1). Transparency of the points. Default
|
annotation_size |
Numeric. Font size for the stats annotation.
Default |
x_axis_title |
Character. Title of the x-axis. Default |
y_axis_title |
Character. Title of the y-axis. If |
title |
Character. Plot title. |
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) loc_coords <- data.frame( Loc = 1:7, lat = 19.0 + seq(0, 0.6, length.out = 7), lon = -99.0 + seq(0, 0.6, length.out = 7) ) metadata$lat <- loc_coords$lat[match(metadata$Loc, loc_coords$Loc)] metadata$lon <- loc_coords$lon[match(metadata$Loc, loc_coords$Loc)] # Jaccard + Spearman Mantel (default) beta_decay_plot( table = table, metadata = metadata, lat_col = "lat", lon_col = "lon" ) # Horn dissimilarity + Spearman Mantel beta_decay_plot( table = table, metadata = metadata, lat_col = "lat", lon_col = "lon", distance = "horn", method = "spearman" ) # Separate Mantel test per location beta_decay_plot( table = table, metadata = metadata, lat_col = "lat", lon_col = "lon", group_col = "Location" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) loc_coords <- data.frame( Loc = 1:7, lat = 19.0 + seq(0, 0.6, length.out = 7), lon = -99.0 + seq(0, 0.6, length.out = 7) ) metadata$lat <- loc_coords$lat[match(metadata$Loc, loc_coords$Loc)] metadata$lon <- loc_coords$lon[match(metadata$Loc, loc_coords$Loc)] # Jaccard + Spearman Mantel (default) beta_decay_plot( table = table, metadata = metadata, lat_col = "lat", lon_col = "lon" ) # Horn dissimilarity + Spearman Mantel beta_decay_plot( table = table, metadata = metadata, lat_col = "lat", lon_col = "lon", distance = "horn", method = "spearman" ) # Separate Mantel test per location beta_decay_plot( table = table, metadata = metadata, lat_col = "lat", lon_col = "lon", group_col = "Location" )
Computes the pairwise beta diversity between samples (shared features, turnover or nestedness) and plots it as box plots, one box per pair of groups.
beta_dissimilarity_plot( table, metadata, comparison_condition1 = NULL, condition1_col, condition2_col = NULL, facet_colors = NULL, group_colors = NULL, x_axis_title = "Condition", y_axis_title = NULL, partition = c("shared", "turnover", "nestedness"), family = c("sorensen", "jaccard"), stat = NULL, p_adjust_method = "holm", show_x_labels = TRUE, x_label_angle = 0, strip_text_bold = FALSE, strip_text_color = "black", aspect_ratio = NULL, save_table = FALSE, table_filename = "betadiv_table.txt" )beta_dissimilarity_plot( table, metadata, comparison_condition1 = NULL, condition1_col, condition2_col = NULL, facet_colors = NULL, group_colors = NULL, x_axis_title = "Condition", y_axis_title = NULL, partition = c("shared", "turnover", "nestedness"), family = c("sorensen", "jaccard"), stat = NULL, p_adjust_method = "holm", show_x_labels = TRUE, x_label_angle = 0, strip_text_bold = FALSE, strip_text_color = "black", aspect_ratio = NULL, save_table = FALSE, table_filename = "betadiv_table.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
comparison_condition1 |
Optional character vector with the pairs of
groups of |
condition1_col |
Character. Name of the column in |
condition2_col |
Character. Name of a second column in |
facet_colors |
Optional character vector of background colors for the
facet strips. If |
group_colors |
Optional character vector of colors, one per comparison
on the x-axis, named after them or in their order. If |
x_axis_title |
Character. Title of the x-axis. Default
|
y_axis_title |
Character. Title of the y-axis. If |
partition |
Type of beta diversity to compute: |
family |
Dissimilarity family for the turnover/nestedness partition:
|
stat |
Character or |
p_adjust_method |
Character. Multiple-testing correction for the
pairwise tests ( |
show_x_labels |
Logical. If |
x_label_angle |
Numeric. Rotation (degrees) of the x-axis labels (when
|
strip_text_bold |
Logical. If |
strip_text_color |
Color of the facet strip labels, which sit on the
|
aspect_ratio |
Numeric. Aspect ratio (height/width) of each panel.
Default |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) beta_dissimilarity_plot( table = table, metadata = metadata, comparison_condition1 = c("Rhizosphere_vs_Roots"), condition1_col = "Location", condition2_col = "Treatment", x_axis_title = "Samples", partition = "shared", family = "sorensen" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) beta_dissimilarity_plot( table = table, metadata = metadata, comparison_condition1 = c("Rhizosphere_vs_Roots"), condition1_col = "Location", condition2_col = "Treatment", x_axis_title = "Samples", partition = "shared", family = "sorensen" )
Computes the beta diversity between samples with several distance metrics (including the compositional CLR/Aitchison distance via ALDEx2) and plots a PCA, PCoA or NMDS ordination.
beta_ord_plot( table, metadata, distance = "compositional", mc_samples = 1, ordination = "PCA", group_col = NULL, palette = "colorb", shape_col = NULL, legend_title = NULL, taxonomy_db = "silva", arrows_size = 10, top_n = 5, title = "auto", save_table = FALSE, table_filename = "ordination_scores.txt", q = 1, diversity = "taxonomic", tree = NULL, traits = NULL, tau = NULL )beta_ord_plot( table, metadata, distance = "compositional", mc_samples = 1, ordination = "PCA", group_col = NULL, palette = "colorb", shape_col = NULL, legend_title = NULL, taxonomy_db = "silva", arrows_size = 10, top_n = 5, title = "auto", save_table = FALSE, table_filename = "ordination_scores.txt", q = 1, diversity = "taxonomic", tree = NULL, traits = NULL, tau = NULL )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
distance |
Distance method: one of |
mc_samples |
Number of ALDEx2 Monte Carlo instances used when
|
ordination |
Ordination method: one of |
group_col |
Character. Name of the column in |
palette |
Either a palette name or a vector of fixed
colors; which scale it produces depends on whether
|
shape_col |
Character. Name of the column in |
legend_title |
Character. Title of the legend. If |
taxonomy_db |
Character. Database the taxonomy strings come from:
|
arrows_size |
Numeric. Size/length scaling factor for biplot arrows. Default |
top_n |
Integer. Number of taxa that contribute most to the PCA, drawn
as arrows. Default |
title |
Character. Plot title. |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
q |
Numeric. Order of the Hill-number dissimilarities |
diversity |
Character. What the Hill-number dissimilarities use:
|
tree |
A rooted |
traits |
A data frame with taxa in rows and traits in columns. Used when
|
tau |
Numeric. Threshold of functional distinctiveness: taxa at this
distance or more count as different functional groups. |
With distance = "compositional" and mc_samples = 1,
the clr values come from one random Monte Carlo instance of
ALDEx2::aldex.clr(); call set.seed() before the function
to make the result reproducible, or use mc_samples = 128.
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) beta_ord_plot( table = table, metadata = metadata, distance = "aitchison", ordination = "NMDS", group_col = "Location", top_n = 5 )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) beta_ord_plot( table = table, metadata = metadata, distance = "aitchison", ordination = "NMDS", group_col = "Location", top_n = 5 )
Partitions the beta diversity (Jaccard or Sorensen) into its turnover and nestedness components with betapart, and plots a PCoA of each component (vegan::betadisper()) with the samples linked to their group centroid.
beta_partition_ord_plot( table, metadata, family = "jaccard", group_col, shape_col = NULL, legend_title = NULL, point_size = 3, group_colors = NULL, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, save_table = FALSE, table_filename = "beta_partition" )beta_partition_ord_plot( table, metadata, family = "jaccard", group_col, shape_col = NULL, legend_title = NULL, point_size = 3, group_colors = NULL, panel_label_case = "upper", panel_labels = NULL, panel_label_bold = TRUE, save_table = FALSE, table_filename = "beta_partition" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
family |
Dissimilarity family for the partition: |
group_col |
Character. Name of the column in |
shape_col |
Character. Name of the column in |
legend_title |
Character. Title of the legend. If |
point_size |
Numeric. Size of the points. Default |
group_colors |
Optional character vector of colors, one per group,
named after the groups or in their order. If |
panel_label_case |
Character. Case of the panel tags: |
panel_labels |
Optional character vector of custom panel tags, one per
panel (Jaccard/Sorensen, turnover, nestedness), used as-is (e.g.
|
panel_label_bold |
Logical. If |
save_table |
Logical. If |
table_filename |
Character. Base name or path of the saved files (used
when |
A patchwork object with the three ordinations
(Jaccard/Sorensen, turnover and nestedness).
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) beta_partition_ord_plot( table = table, metadata = metadata, group_col = "Location", point_size = 4 )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) beta_partition_ord_plot( table = table, metadata = metadata, group_col = "Location", point_size = 4 )
Runs a PERMANOVA (vegan::adonis2()) or a test of homogeneity of dispersions (vegan::betadisper()) on the distances between samples and returns the results as a table figure.
beta_test_table( table, metadata, formula_str, distance = "euclidean", test = c("permanova", "betadisper"), permutations = 999, mc_samples = 1, strata_var = NULL, digits = 3, save_table = FALSE, table_filename = "beta_test_results.txt", q = 1, diversity = "taxonomic", tree = NULL, traits = NULL, tau = NULL )beta_test_table( table, metadata, formula_str, distance = "euclidean", test = c("permanova", "betadisper"), permutations = 999, mc_samples = 1, strata_var = NULL, digits = 3, save_table = FALSE, table_filename = "beta_test_results.txt", q = 1, diversity = "taxonomic", tree = NULL, traits = NULL, tau = NULL )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
formula_str |
Character. Right-hand side of the model formula, with
columns of |
distance |
Character. Distance metric: |
test |
Statistical test to run: one of |
permutations |
Integer. Number of permutations for the test. Default
|
mc_samples |
Number of ALDEx2 Monte Carlo instances used when
|
strata_var |
Character. Name of a column in |
digits |
Integer. Decimal places of the numeric columns (except the
p-value). Default |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
q |
Numeric. Order of the Hill-number dissimilarities |
diversity |
Character. What the Hill-number dissimilarities use:
|
tree |
A rooted |
traits |
A data frame with taxa in rows and traits in columns. Used when
|
tau |
Numeric. Threshold of functional distinctiveness: taxa at this
distance or more count as different functional groups. |
The first column of metadata must hold the sample IDs;
metadata rows are matched to the samples by ID, so their order doesn't
matter. A precomputed distance is used as-is (distance is ignored).
The p-values come from permutations; call set.seed() before the
function to make the result reproducible.
A ggplot object (ggpubr::ggtexttable()) with the results
table; significant p-values are in bold. Use save_table = TRUE
to get the results as a tab-delimited file.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # Example using a data frame beta_test_table( table = table, metadata = metadata, formula_str = "Location*Treatment", distance = "bray", test = "permanova", permutations = 999, strata_var = "Plot" ) # Example using a distance matrix dist_matrix <- vegan::vegdist( t(table[, setdiff(colnames(table), "taxonomy")]), method = "bray" ) beta_test_table( table = dist_matrix, metadata = metadata, formula_str = "Location", test = "betadisper" ) # Compositional PERMANOVA (CLR via ALDEx2, then Euclidean) beta_test_table( table = table, metadata = metadata, formula_str = "Location", distance = "compositional", test = "permanova", permutations = 999 )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # Example using a data frame beta_test_table( table = table, metadata = metadata, formula_str = "Location*Treatment", distance = "bray", test = "permanova", permutations = 999, strata_var = "Plot" ) # Example using a distance matrix dist_matrix <- vegan::vegdist( t(table[, setdiff(colnames(table), "taxonomy")]), method = "bray" ) beta_test_table( table = dist_matrix, metadata = metadata, formula_str = "Location", test = "betadisper" ) # Compositional PERMANOVA (CLR via ALDEx2, then Euclidean) beta_test_table( table = table, metadata = metadata, formula_str = "Location", distance = "compositional", test = "permanova", permutations = 999 )
Computes the pairwise beta diversity between samples with Hill numbers
(q = 0, 1, 2; same values as hillR::hill_taxa_parti_pairwise()) and
plots the proportion of feature turnover (, from 0 = identical
to 1 = no shared features) as box plots, one facet row per Hill order.
q = 0 weighs all features equally (presence/absence), q = 1 weighs them by
their abundance and q = 2 gives more weight to dominant features.
beta_turnover_plot( table, metadata, comparison_condition1, comparison_condition2 = NULL, condition1_col, condition2_col = NULL, facet_colors = NULL, group_colors = NULL, x_axis_title = "Section", y_axis_title = "Proportion of feature turnover", show_x_labels = FALSE, x_label_angle = 0, strip_text_bold = FALSE, strip_text_color = "white", aspect_ratio = NULL, stat = NULL, p_adjust_method = "holm", save_table = FALSE, table_filename = "betadiv_turnover.txt" )beta_turnover_plot( table, metadata, comparison_condition1, comparison_condition2 = NULL, condition1_col, condition2_col = NULL, facet_colors = NULL, group_colors = NULL, x_axis_title = "Section", y_axis_title = "Proportion of feature turnover", show_x_labels = FALSE, x_label_angle = 0, strip_text_bold = FALSE, strip_text_color = "white", aspect_ratio = NULL, stat = NULL, p_adjust_method = "holm", save_table = FALSE, table_filename = "betadiv_turnover.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
comparison_condition1 |
Character vector with the pairs of groups of
|
comparison_condition2 |
Optional character vector with the pairs of
groups of |
condition1_col |
Character. Name of the column in |
condition2_col |
Optional. Metadata column used to build
|
facet_colors |
Optional character vector of background colors for the
facet strips. If |
group_colors |
Optional character vector of colors, one per comparison
on the x-axis, named after them or in their order. If |
x_axis_title |
Character. Title of the x-axis. Default
|
y_axis_title |
Character. Title of the y-axis. Default
|
show_x_labels |
Logical. If |
x_label_angle |
Numeric. Rotation (degrees) of the x-axis labels (when
|
strip_text_bold |
Logical. If |
strip_text_color |
Color of the top (x) facet strip labels, which sit on
the |
aspect_ratio |
Numeric. Aspect ratio (height/width) of each panel.
Default |
stat |
Character or |
p_adjust_method |
Character. Multiple-testing correction for the
pairwise tests ( |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
Each box is one group pair from condition1_col, so a between-group
comparison (e.g. "Rhizosphere_vs_Roots") can be contrasted with a
within-group baseline (e.g. "Rhizosphere_vs_Rhizosphere"): if the
between-group turnover is higher, the groups host distinct communities
beyond the variability among replicates of the same group. An optional
condition2_col keeps only pairs from the same level (e.g. the same
treatment) and facets by it, so the comparison is not confounded by it.
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) colnames(metadata)[1] <- "OTUID" # comparison_condition1/2 match group pairs regardless of order, so listing # "Rhizosphere_vs_Roots" also catches pairs the self-join recorded the # other way around ("Roots_vs_Rhizosphere") - no need to list both. beta_turnover_plot( table = table, metadata = metadata, comparison_condition1 = c("Rhizosphere_vs_Roots", "Rhizosphere_vs_Rhizosphere"), comparison_condition2 = c("Control_vs_Control", "Moderate_drought_vs_Moderate_drought"), condition1_col = "Location", condition2_col = "Treatment", facet_colors = c("#5D478B", "#8B668B"), group_colors = c( "Rhizosphere_vs_Roots" = "#56B4E9", "Rhizosphere_vs_Rhizosphere" = "#E69F00" ) )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) colnames(metadata)[1] <- "OTUID" # comparison_condition1/2 match group pairs regardless of order, so listing # "Rhizosphere_vs_Roots" also catches pairs the self-join recorded the # other way around ("Roots_vs_Rhizosphere") - no need to list both. beta_turnover_plot( table = table, metadata = metadata, comparison_condition1 = c("Rhizosphere_vs_Roots", "Rhizosphere_vs_Rhizosphere"), comparison_condition2 = c("Control_vs_Control", "Moderate_drought_vs_Moderate_drought"), condition1_col = "Location", condition2_col = "Treatment", facet_colors = c("#5D478B", "#8B668B"), group_colors = c( "Rhizosphere_vs_Roots" = "#56B4E9", "Rhizosphere_vs_Rhizosphere" = "#E69F00" ) )
Performs a Canonical Correspondence Analysis (CCA) or a Redundancy Analysis (RDA) of the abundance table constrained by environmental variables, and plots the samples and the environmental vectors as a biplot.
cca_rda_biplot( table, env_data = NULL, env_vars, method = "hell", metadata, group_col = NULL, group_colors = NULL, legend_title = NULL, scale_env = TRUE, pval_threshold = 0.05, p_adjust_method = "none", show_all_env_vectors = FALSE, analysis = "CCA", scale_arrows = 1, title = "auto", save_table = FALSE, table_filename = "cca_rda_scores.txt" )cca_rda_biplot( table, env_data = NULL, env_vars, method = "hell", metadata, group_col = NULL, group_colors = NULL, legend_title = NULL, scale_env = TRUE, pval_threshold = 0.05, p_adjust_method = "none", show_all_env_vectors = FALSE, analysis = "CCA", scale_arrows = 1, title = "auto", save_table = FALSE, table_filename = "cca_rda_scores.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
env_data |
Optional data frame of environmental variables, with row
names matching the sample names in |
env_vars |
A character vector with the names of environmental variables
(columns of |
method |
Character. Transformation of the abundances, passed to
|
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
group_col |
Character. Name of the column in |
group_colors |
Optional character vector of colors, one per group,
named after the groups or in their order. If |
legend_title |
Character. Title of the legend. If |
scale_env |
Logical. If |
pval_threshold |
Numeric. P-value cutoff (after |
p_adjust_method |
Character. Multiple-testing correction for the
|
show_all_env_vectors |
Logical. If |
analysis |
Constrained ordination method: |
scale_arrows |
Numeric. Multiplies the length of the environmental
arrows; it only changes how they are drawn. Default |
title |
Character. Plot title. |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
The p-values of the environmental vectors come from
vegan::envfit() permutations; call set.seed() before the
function to make them reproducible.
A ggplot object with the biplot. The axis titles show the percentage of the variance (inertia) explained by each constrained axis.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # The environmental variables are columns of metadata, chosen with env_vars cca_rda_biplot( table = table, metadata = metadata, env_vars = c("pH", "TOC", "FW", "Root_FW", "DW"), analysis = "RDA", show_all_env_vectors = TRUE, group_col = "Location" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) # The environmental variables are columns of metadata, chosen with env_vars cca_rda_biplot( table = table, metadata = metadata, env_vars = c("pH", "TOC", "FW", "Root_FW", "DW"), analysis = "RDA", show_all_env_vectors = TRUE, group_col = "Location" )
Collapses an abundance table to a taxonomic level (e.g. genus, family, phylum), summing the counts of the features that share the same taxonomy. Features not resolved to that level keep their deepest assigned rank and are also summed when they share the same taxonomy. Optionally converts the counts to relative abundance and saves the collapsed table.
collapse_table( table, level = "genus", rel_abun = FALSE, save_table = FALSE, table_filename = "collapsed_table.txt" )collapse_table( table, level = "genus", rel_abun = FALSE, save_table = FALSE, table_filename = "collapsed_table.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
level |
Character. Taxonomic level: |
rel_abun |
Logical. If |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A list with two elements: collapsed_table (wide format,
one row per collapsed taxon) and long_format (the same data
pivoted to one row per taxon/sample combination).
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) collapse_table( table = table, level = "genus", rel_abun = FALSE, save_table = FALSE )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) collapse_table( table = table, level = "genus", rel_abun = FALSE, save_table = FALSE )
Computes the relative abundance of the taxa at a taxonomic level, correlates it with environmental variables, and shows the correlations as a heatmap (tile) or a bubble plot (circle).
corr_env_abund_plot( table, env_data = NULL, metadata = NULL, env_vars = NULL, method = "spearman", hc.order = TRUE, geom = c("tile", "circle"), show_labels = TRUE, col_palette = NULL, diverging_palette = "BuOr", invert_axes = TRUE, taxonomy_db = "silva", level = "genus", pval_threshold = NULL, p_adjust_method = "BH", x_label_angle = 45, save_table = FALSE, table_filename = "corr.txt" )corr_env_abund_plot( table, env_data = NULL, metadata = NULL, env_vars = NULL, method = "spearman", hc.order = TRUE, geom = c("tile", "circle"), show_labels = TRUE, col_palette = NULL, diverging_palette = "BuOr", invert_axes = TRUE, taxonomy_db = "silva", level = "genus", pval_threshold = NULL, p_adjust_method = "BH", x_label_angle = 45, save_table = FALSE, table_filename = "corr.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
env_data |
Optional data frame of environmental variables, with row
names matching the sample names in |
metadata |
A data frame containing sample metadata.
Its first column must hold the sample IDs (the column names of |
env_vars |
Character vector of environmental variables to include in
the correlation analysis (columns of |
method |
Character. Correlation method: |
hc.order |
Logical. If |
geom |
Character. Type of visualization to generate: |
show_labels |
Logical. If |
col_palette |
Optional character vector of colors for the correlation
scale. If |
diverging_palette |
Character. Colorblind-friendly diverging palette,
used when |
invert_axes |
Logical. If |
taxonomy_db |
Character. Database the taxonomy strings come from:
|
level |
Character. Taxonomic level: |
pval_threshold |
Numeric or |
p_adjust_method |
Character. Multiple-testing correction for the
p-values of all taxon x variable correlations, any method of
|
x_label_angle |
Numeric. Rotation (degrees) of the x-axis labels.
Default |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) corr_env_abund_plot( table = table, metadata = metadata, env_vars = c("pH", "TOC", "FW", "Root_FW", "DW", "Root_L", "Stem_L"), method = "pearson", geom = "tile", hc.order = FALSE, invert_axes = TRUE, show_labels = FALSE, level = "phylum", taxonomy_db = "silva" )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) corr_env_abund_plot( table = table, metadata = metadata, env_vars = c("pH", "TOC", "FW", "Root_FW", "DW", "Root_L", "Stem_L"), method = "pearson", geom = "tile", hc.order = FALSE, invert_axes = TRUE, show_labels = FALSE, level = "phylum", taxonomy_db = "silva" )
Extracts the count table, taxonomy and sample metadata of a
phyloseq object into the plain data frames that every
MicroBioMeta function takes.
from_phyloseq(physeq)from_phyloseq(physeq)
physeq |
A |
A list with two data frames:
tableTaxa in rows, samples in columns, and a last
column taxonomy with the full taxonomic string
(e.g. "k__Bacteria; p__Firmicutes; c__Bacilli").
metadataSample metadata whose first column,
SAMPLEID, holds the sample names of table.
from_tse for (Tree)SummarizedExperiment
objects.
if (requireNamespace("phyloseq", quietly = TRUE)) { counts <- matrix(c(10, 0, 5, 3, 8, 1), nrow = 3, dimnames = list(c("ASV1", "ASV2", "ASV3"), c("S1", "S2")) ) tax <- matrix( c( "Bacteria", "Bacteria", "Bacteria", "Firmicutes", "Proteobacteria", NA ), nrow = 3, dimnames = list(rownames(counts), c("Kingdom", "Phylum")) ) samples <- data.frame( Soil = c("Rhizosphere", "Bulk soil"), row.names = c("S1", "S2") ) ps <- phyloseq::phyloseq( phyloseq::otu_table(counts, taxa_are_rows = TRUE), phyloseq::tax_table(tax), phyloseq::sample_data(samples) ) mbm <- from_phyloseq(ps) mbm$table mbm$metadata }if (requireNamespace("phyloseq", quietly = TRUE)) { counts <- matrix(c(10, 0, 5, 3, 8, 1), nrow = 3, dimnames = list(c("ASV1", "ASV2", "ASV3"), c("S1", "S2")) ) tax <- matrix( c( "Bacteria", "Bacteria", "Bacteria", "Firmicutes", "Proteobacteria", NA ), nrow = 3, dimnames = list(rownames(counts), c("Kingdom", "Phylum")) ) samples <- data.frame( Soil = c("Rhizosphere", "Bulk soil"), row.names = c("S1", "S2") ) ps <- phyloseq::phyloseq( phyloseq::otu_table(counts, taxa_are_rows = TRUE), phyloseq::tax_table(tax), phyloseq::sample_data(samples) ) mbm <- from_phyloseq(ps) mbm$table mbm$metadata }
Extracts one assay (the counts), the taxonomy (rowData) and the
sample metadata (colData) of a TreeSummarizedExperiment or
any other SummarizedExperiment, e.g. one built with the
mia package, into the plain data frames that every MicroBioMeta
function takes.
from_tse(tse, assay_name = "counts")from_tse(tse, assay_name = "counts")
tse |
A |
assay_name |
Character. Name of the assay with the counts. Default
|
A list with two data frames:
tableTaxa in rows, samples in columns, and a last
column taxonomy with the full taxonomic string
(e.g. "k__Bacteria; p__Firmicutes; c__Bacilli").
metadataSample metadata whose first column,
SAMPLEID, holds the sample names of table.
The taxonomy is built from the rowData columns named after
taxonomic ranks (Kingdom or Domain, Phylum, Class, Order, Family,
Genus, Species; any case). If rowData already has a
taxonomy column, it is used as is.
from_phyloseq for phyloseq objects.
if (requireNamespace("SummarizedExperiment", quietly = TRUE)) { counts <- matrix(c(10, 0, 5, 3, 8, 1), nrow = 3, dimnames = list(c("ASV1", "ASV2", "ASV3"), c("S1", "S2")) ) tax <- data.frame( Kingdom = "Bacteria", Phylum = c("Firmicutes", "Proteobacteria", NA), row.names = rownames(counts) ) samples <- data.frame( Soil = c("Rhizosphere", "Bulk soil"), row.names = c("S1", "S2") ) se <- SummarizedExperiment::SummarizedExperiment( assays = list(counts = counts), rowData = tax, colData = samples ) mbm <- from_tse(se) mbm$table mbm$metadata }if (requireNamespace("SummarizedExperiment", quietly = TRUE)) { counts <- matrix(c(10, 0, 5, 3, 8, 1), nrow = 3, dimnames = list(c("ASV1", "ASV2", "ASV3"), c("S1", "S2")) ) tax <- data.frame( Kingdom = "Bacteria", Phylum = c("Firmicutes", "Proteobacteria", NA), row.names = rownames(counts) ) samples <- data.frame( Soil = c("Rhizosphere", "Bulk soil"), row.names = c("S1", "S2") ) se <- SummarizedExperiment::SummarizedExperiment( assays = list(counts = counts), rowData = tax, colData = samples ) mbm <- from_tse(se) mbm$table mbm$metadata }
This function joins a feature table (counts per sample) with the corresponding taxonomy data.
merge_feature_taxonomy( table, taxonomy, save_table = FALSE, table_filename = "merged_feature_taxonomy.txt" )merge_feature_taxonomy( table, taxonomy, save_table = FALSE, table_filename = "merged_feature_taxonomy.txt" )
table |
A data frame with features in rows and samples in columns. Row
names must hold the feature IDs (OTUs, ASVs, species...). If the table has
no row names (e.g. read without |
taxonomy |
A data frame or matrix with the taxonomy. Row names (or, if
absent, the first column) must hold the feature IDs of |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A data frame with the counts of table and the taxonomy
columns. A single taxonomy column is renamed to taxonomy.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") full_table <- read.delim(table_path, row.names = 1, check.names = FALSE) feature_table <- full_table[, setdiff(colnames(full_table), "taxonomy")] taxonomy_df <- full_table[, "taxonomy", drop = FALSE] merged <- merge_feature_taxonomy( table = feature_table, taxonomy = taxonomy_df )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") full_table <- read.delim(table_path, row.names = 1, check.names = FALSE) feature_table <- full_table[, setdiff(colnames(full_table), "taxonomy")] taxonomy_df <- full_table[, "taxonomy", drop = FALSE] merged <- merge_feature_taxonomy( table = feature_table, taxonomy = taxonomy_df )
Fits a random forest (randomForest) that predicts a metadata variable from the abundances, and plots the most important features as a lollipop plot colored by phylum.
random_forest_lollipop_plot( table, metadata, top_n = 15, size = 8, variable_to_predict, group_colors = NULL, title = NULL, save_table = FALSE, table_filename = "randomforest_importance.txt", x_axis_title = "Feature importance (MeanDecreaseGini)" )random_forest_lollipop_plot( table, metadata, top_n = 15, size = 8, variable_to_predict, group_colors = NULL, title = NULL, save_table = FALSE, table_filename = "randomforest_importance.txt", x_axis_title = "Feature importance (MeanDecreaseGini)" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
top_n |
Integer. Number of most important features to show. Default
|
size |
Numeric. Size of the lollipop points. Default |
variable_to_predict |
Character. Name of the column in |
group_colors |
Optional character vector of colors, one per phylum
(recycled if shorter). If |
title |
Character. Plot title. |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
x_axis_title |
Character. Title of the x-axis (feature importance).
Default |
The random forest is random; call set.seed() before the
function to make the result reproducible.
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) random_forest_lollipop_plot( table = table, metadata = metadata, variable_to_predict = "Location", top_n = 20, size = 6 )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) random_forest_lollipop_plot( table = table, metadata = metadata, variable_to_predict = "Location", top_n = 20, size = 6 )
Computes relative abundances from a taxonomic abundance table and compares two experimental conditions by calculating a directional abundance ratio for each taxon.
ratios_bubble_plot( table, metadata, group_col, condition_A, condition_B, taxonomy_db = "silva", top_n = 30, level = "genus", x_axis_title = "Taxon", legend_title = NULL, group_colors = NULL, save_table = FALSE, table_filename = "ratios_bubble_table.txt" )ratios_bubble_plot( table, metadata, group_col, condition_A, condition_B, taxonomy_db = "silva", top_n = 30, level = "genus", x_axis_title = "Taxon", legend_title = NULL, group_colors = NULL, save_table = FALSE, table_filename = "ratios_bubble_table.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
group_col |
Character. Name of the column in |
condition_A |
Character. Name of the first condition to compare. |
condition_B |
Character. Name of the second condition to compare. |
taxonomy_db |
Character. Database the taxonomy strings come from:
|
top_n |
Integer. Number of taxa with the highest mean abundance to
show. Default |
level |
Character. Taxonomic level: |
x_axis_title |
Character. Title of the x-axis (taxon names). Default
|
legend_title |
Character. Title of the legend and of the axis showing
the dominant condition. If |
group_colors |
Optional character vector of two colors, one per
condition. If |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) ratios_bubble_plot( table = table, metadata = metadata, group_col = "Location", condition_A = "Rhizosphere", condition_B = "Roots", taxonomy_db = "silva", level = "genus", top_n = 20 )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) ratios_bubble_plot( table = table, metadata = metadata, group_col = "Location", condition_A = "Rhizosphere", condition_B = "Roots", taxonomy_db = "silva", level = "genus", top_n = 20 )
Creates a Venn diagram of the taxa shared between groups of samples, with ggvenn or ggVennDiagram.
venn_plot( table, metadata, merge_by, selected_samples = NULL, min_prevalence = 0, title = NULL, method = "ggvenn", group_colors = NULL, save_table = FALSE, table_filename = "venn_taxa_sets.txt" )venn_plot( table, metadata, merge_by, selected_samples = NULL, min_prevalence = 0, title = NULL, method = "ggvenn", group_colors = NULL, save_table = FALSE, table_filename = "venn_taxa_sets.txt" )
table |
A data frame with taxa in rows and samples in columns.
The last column must be named |
metadata |
A data frame containing sample metadata. Its first column
must hold the sample IDs (the column names of |
merge_by |
Character. Name of the column in |
selected_samples |
Optional character vector of the sample IDs to use.
If |
min_prevalence |
Numeric (0-1). Minimum fraction of the samples of a
group where a taxon must be present to count it in that group. Default
|
title |
Character. Plot title. |
method |
Character. Package used to draw the Venn diagram: |
group_colors |
Optional character vector of colors, one per group,
named after the groups or in their order. If |
save_table |
Logical. If |
table_filename |
Character. Name or path of the saved file (used when
|
A ggplot object.
table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) venn_plot( table = table, metadata = metadata, merge_by = "Location", min_prevalence = 0 ) ## Filtering taxa by prevalence venn_plot( table = table, metadata = metadata, merge_by = "Location", min_prevalence = 0.2 ) ## Custom colors venn_plot( table = table, metadata = metadata, merge_by = "Location", min_prevalence = 0, group_colors = c("#1B9E77", "#D95F02") )table_path <- system.file("extdata", "subset_table_bacteria.txt", package = "MicroBioMeta") table <- read.delim(table_path, row.names = 1, check.names = FALSE) metadata_path <- system.file("extdata", "subset_metadata_bacteria.txt", package = "MicroBioMeta") metadata <- read.delim(metadata_path, check.names = FALSE) venn_plot( table = table, metadata = metadata, merge_by = "Location", min_prevalence = 0 ) ## Filtering taxa by prevalence venn_plot( table = table, metadata = metadata, merge_by = "Location", min_prevalence = 0.2 ) ## Custom colors venn_plot( table = table, metadata = metadata, merge_by = "Location", min_prevalence = 0, group_colors = c("#1B9E77", "#D95F02") )