This function calculates beta diversity (shared species, turnover, or nestedness) and generates a ggplot2 boxplot with facets and custom coloring. The user only needs to specify the metadata column(s) to be used for comparisons; the function constructs the comparison pairs internally and removes duplicates (A_vs_B = B_vs_A).
beta_diversity_boxplot(
table,
metadata,
comparison_condition1 = NULL,
condition1_col,
condition2_col = NULL,
color_facets_x = NULL,
color_axis_x = NULL,
title_axis_x = "Condition",
partition = c("shared", "turnover", "nestedness"),
family = c("sorensen", "jaccard"),
save_table = TRUE,
table_filename = "betadiv_table.txt"
)Abundance matrix (samples in columns, species/features in rows).
Data frame with sample metadata. First column must match sample names in table.
Optional vector of comparison labels for the first condition.
Column name in metadata for the first condition.
Optional column name in metadata for the second condition (used as facet).
Optional vector of colors for facet strips. Defaults to RColorBrewer "Set2".
Optional named vector of colors for x-axis groups. Defaults to RColorBrewer "Set2".
Title for the x-axis.
Type of beta diversity to compute: "shared", "turnover", or "nestedness".
Family for turnover/nestedness calculation: "sorensen" or "jaccard".
A ggplot2 figure object.
beta_diversity_boxplot(table = table,
metadata = metadata,
comparison_condition1 = c("fenol_vs_kit"),
condition1_col = "metodo",
condition2_col = "edad",
title_axis_x = "Samples",
partition = "shared", family = "sorensen")
#> Installing package into 'C:/Users/Nestor/AppData/Local/Temp/RtmpaCNPW9/temp_libpath3cfc7e5055bf'
#> (as 'lib' is unspecified)
#> also installing the dependencies 'picante', 'rcdd', 'doSNOW', 'itertools', 'minpack.lm'
#> package 'picante' successfully unpacked and MD5 sums checked
#> package 'rcdd' successfully unpacked and MD5 sums checked
#> package 'doSNOW' successfully unpacked and MD5 sums checked
#> package 'itertools' successfully unpacked and MD5 sums checked
#> package 'minpack.lm' successfully unpacked and MD5 sums checked
#> package 'betapart' successfully unpacked and MD5 sums checked
#>
#> The downloaded binary packages are in
#> C:\Users\Nestor\AppData\Local\Temp\RtmpcBYvwG\downloaded_packages
#> Error in table > 0: comparison (>) is possible only for atomic and list types