This function calculates the relative abundances of taxa at a specified taxonomic level (phylum, genus, or species) from a count table, computes correlations between these abundances and environmental variables, and visualizes the results as either a heatmap (tile) or a bubble plot (circle).

corr_env_abund_plot(
  table,
  env_table,
  metadata,
  cond_vect = NULL,
  method = "spearman",
  hc.order = TRUE,
  geom = c("tile", "circle"),
  show_labels = TRUE,
  col_palette = NULL,
  invert_axes = TRUE,
  taxonomy_db = "silva",
  level = "genus",
  pval_threshold = NULL,
  save_table = TRUE,
  table_filename = "corr.txt"
)

Arguments

table

A data frame containing a taxonomic abundance table with a taxonomy column and sample columns with numeric counts.

env_table

A data frame or matrix of environmental variables, with samples as row names.

metadata

A data frame containing sample metadata. The first column must correspond to sample identifiers.

cond_vect

Character vector of environmental variables to include in the correlation analysis. If NULL, all available variables are used.

method

Character. Correlation method passed to stats::cor and stats::cor.test. Supported options include ("spearman", "pearson", "kendall").

hc.order

Logical. If TRUE, applies hierarchical clustering to reorder taxa and environmental variables in the plot.

geom

Character. Type of visualization to generate: "tile" (heatmap) or "circle" (bubble plot).

show_labels

Logical. If TRUE, displays correlation values on the plot.

col_palette

Character vector defining the color palette for correlation values. If NULL, a blue–white–red palette is used.

invert_axes

Logical. If TRUE, swaps x and y axes in the plot.

taxonomy_db

Character. Taxonomic database used for annotation and parsing. Supported options include ("silva", "unite","Kraken2" and "gg2").

level

Character. Taxonomic level to collapse taxa to. One of ("kingdom", "phylum", "class", "order", "family", "genus", "species").

pval_threshold

Numeric. Optional p-value threshold to retain only taxa showing significant correlations with at least one environmental variable. If NULL, no significance filtering is applied.

save_table

Logical. If TRUE, saves the correlation matrix as a tab-delimited text file.

table_filename

Character. Name of the output file used when save_table = TRUE.

Value

A ggplot2 object.

Examples

color<- c("pink","white","purple")