R/corr_env_abun_plot.R
corr_env_abund_plot.RdThis 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"
)A data frame containing a taxonomic abundance table with a taxonomy column and sample columns with numeric counts.
A data frame or matrix of environmental variables, with samples as row names.
A data frame containing sample metadata. The first column must correspond to sample identifiers.
Character vector of environmental variables to include in the correlation analysis. If NULL, all available variables are used.
Character. Correlation method passed to stats::cor and stats::cor.test. Supported options include ("spearman", "pearson", "kendall").
Logical. If TRUE, applies hierarchical clustering to reorder taxa and environmental variables in the plot.
Character. Type of visualization to generate: "tile" (heatmap) or "circle" (bubble plot).
Logical. If TRUE, displays correlation values on the plot.
Character vector defining the color palette for correlation values. If NULL, a blue–white–red palette is used.
Logical. If TRUE, swaps x and y axes in the plot.
Character. Taxonomic database used for annotation and parsing. Supported options include ("silva", "unite","Kraken2" and "gg2").
Character. Taxonomic level to collapse taxa to. One of ("kingdom", "phylum", "class", "order", "family", "genus", "species").
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.
Logical. If TRUE, saves the correlation matrix as a tab-delimited text file.
Character. Name of the output file used when save_table = TRUE.
A ggplot2 object.
color<- c("pink","white","purple")