Generates a ggplot2-based UpSet plot to visualize the intersection patterns of taxa across different sample groups. This provides a scalable alternative to Venn diagrams for microbiome data.
Usage
plot_taxa_upset(
me,
tax_rank,
group_var,
plot_title = NULL,
show_names = FALSE,
group_labels = NULL,
min_abundance = 0,
min_prevalence = 0,
filter_by_group = FALSE,
text_size = 2,
...
)Arguments
- me
A
microEDAorphyloseqobject containing OTU table, taxonomy, and sample data.- tax_rank
Characterstring specifying the taxonomic rank to plot (e.g., "Phylum", "Family"). Must be a valid rank in the taxonomy table.- group_var
Characterstring indicating a sample metadata variable to group samples.- plot_title
Optional
characterstring for the plot title. IfNULL, a default title is generated based ontax_rank.- show_names
Logical. IfTRUE, displays taxon names on intersection bars with italicized formatting. Default isFALSE.- group_labels
Named character
vectormapping old group names to new labels (e.g.,c("Old" = "New")).- min_abundance
Numericvalue. Minimum abundance threshold for a feature to be retained. Must be non-negative. Features with abundance below this are considered absent.- min_prevalence
Numericvalue. Minimum prevalence required for retention. If value is < 1, interpreted as proportion of samples; otherwise, as absolute number of samples.- filter_by_group
Logical. IfFALSE(default), filtering is applied globally across all samples even ifgroup_varis specified. This allows usinggroup_varfor stratification in plotting without affecting the filtering scope. IfTRUE, filtering is applied within each group defined bygroup_varandgroup_requirement. See filter_features for more details on filtering arguments.- text_size
Numeric. Font size for taxon labels whenshow_names = TRUE. Default is 2.- ...
Additional arguments for fine-tuning. Can include:
abundance_criterion:Characterstring. Criterion to use for filtering:prevalence:Retain features present in at least
min_prevalencesamples (within group ifgroup_varis used) and with abundance >=min_abundancein those samples.mean:Also requires that the mean abundance across samples (or group) is >=
min_abundance.
Default:
"prevalence".group_requirement:Characterstring. Whengroup_varis specified, determines whether the filter criterion must be met in"any"group or"all"groups. Default:"any".keep_filtered: Whether to keep filtered out taxa as "Other" (Default:TRUE). Takes effect only formicroEDAobjects.rm_missing:Logical.IfTRUE, removes taxa with missing/unclassified entries at the specified rank. IfFALSE, fills missing values by propagating the last known ancestor, labeling them as "Unclassified Last_Known_Parent_Clade" (e.g., "Unclassified Enterobacteriaceae"). (Default:FALSE).
Details
The function performs the following steps:
Validates the input
meobject.Filters taxa by
min_abundance,min_prevalence.Aggregates counts by
tax_rank.Determines taxon presence/absence per sample group.
Constructs an UpSet plot using the
ComplexUpsetpackage.
Taxon names are formatted in italics when show_names = TRUE.
Examples
data(GlobalPatterns, package = "phyloseq")
plot_taxa_upset(GlobalPatterns, "Phylum", "SampleType")
#> Warning: Both 'min_abundance' and 'min_prevalence' are 0. No filtering will be applied.
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` instead.
#> ℹ The deprecated feature was likely used in the ComplexUpset package.
#> Please report the issue at
#> <https://github.com/krassowski/complex-upset/issues>.