Reorder taxa in phyloseq object using vector of names
tax_reorder(
ps,
tax_order,
tree_warn = TRUE,
unmatched_warn = TRUE,
ignore = c("other", "Other")
)
phyloseq object
Names of taxa in desired order; at least some must match. (Numerical indices are also possible)
If phylogenetic tree is present in phyloseq phy_tree slot, taxa cannot be reordered. Default behaviour of tax_sort is to remove the phylogenetic tree and warn about this. tree_warn = FALSE will suppress the warning message, but still remove the tree!
Warn if any names (or indices) given in tax_order are not found within (range of) taxa_names(ps) - these will be ignored
Values that you do not want to be used for reordering taxa (useful for comp_barplot when custom palette names are used to set tax_order)
phyloseq object (always without phy_tree)
data("dietswap", package = "microbiome")
new_order <- c(
"Fusobacteria", "Cyanobacteria", "Verrucomicrobia", "Spirochaetes",
"Actinobacteria", "Firmicutes", "Proteobacteria", "Bacteroidetes"
)
tax_agg(dietswap, rank = "Phylum") %>%
ps_get() %>%
phyloseq::taxa_names()
#> [1] "Actinobacteria" "Firmicutes" "Proteobacteria" "Verrucomicrobia"
#> [5] "Bacteroidetes" "Spirochaetes" "Fusobacteria" "Cyanobacteria"
tax_agg(dietswap, rank = "Phylum") %>%
ps_get() %>%
tax_reorder(tax_order = new_order) %>%
phyloseq::taxa_names()
#> [1] "Fusobacteria" "Cyanobacteria" "Verrucomicrobia" "Spirochaetes"
#> [5] "Actinobacteria" "Firmicutes" "Proteobacteria" "Bacteroidetes"
# partial reordering (of the frontmost positions only) is possible
tax_agg(dietswap, rank = "Phylum") %>%
ps_get() %>%
tax_reorder(tax_order = c("Cyanobacteria", "Bacteroidetes")) %>%
phyloseq::taxa_names()
#> [1] "Cyanobacteria" "Bacteroidetes" "Actinobacteria" "Firmicutes"
#> [5] "Proteobacteria" "Verrucomicrobia" "Spirochaetes" "Fusobacteria"