1

I want to make a barplot using the library fantaxtic (top taxa: Phylum and nested taxa Genus). The problem is that I want to filter Genus by abundance > 2% and the rest of phyla I want to group them in the category Others. Is it posible? Can library Fantaxtic filter by abundance?

I found an answer in this forum suggesting something like that

get_top_taxa(glom_genus, 0.98*nrow(glom_genus@otu_table))

but it is not working for me. I read that get_top_taxa is deprecated.

Marco
  • 2,368
  • 6
  • 22
  • 48
  • It seems that you want to use this function instead https://rdrr.io/github/gmteunisse/Fantaxtic/man/top_taxa.html – Phil Jul 06 '23 at 18:16
  • Yes, I tried..but I do not know how to ask to the command that I want to filter the taxa > 2% and that the function creates a category named 'Other' with the taxa < 2% – user1892205 Jul 07 '23 at 03:19

1 Answers1

1

I'm the author of the package, and I have to disappoint you: top_taxa only returns the top N taxa by some metric. This is by design: a plot with too many taxa in it simply becomes unintelligible, and tight control over the number of taxa is therefore required.

Luckily, you can apply your own manual filtering and use fantaxtic::collapse_taxa to then create a phyloseq object where all taxa <2% are merged. See the code below for a full example.

Note: you need to decide how 2% is calculated: is this a minimum abundance of 2%, a mean abundance of 2%, a summed abundance of 2%, etc. In the example below I used the maximum, and set the cutoff to 10% to prevent overplotting.

In the future, feel free to create an issue in the fantaxtic repository on GitHub; this will ensure that I can quickly and accurately answer your question.

require("phyloseq")
require("tidyverse")
require("fantaxtic")

# Load data
data(GlobalPatterns)

# Subset to max >10%
ps_genus <- tax_glom(GlobalPatterns, taxrank = "Genus", NArm = FALSE)
rel_abun <- transform_sample_counts(ps_genus, function(x) x / sum(x) )
pass <- filter_taxa(rel_abun, function(x) max(x) > 0.1, FALSE)
ids <- names(pass)[pass]
ps_genus_filtered <- collapse_taxa(ps_genus, taxa_to_keep = ids)

# Plot
plot_nested_bar(ps_genus_filtered, top_level = "Phylum", nested_level = "Genus")

Created on 2023-07-12 by the reprex package (v2.0.1)

gmt
  • 325
  • 1
  • 7