tax_sort | R Documentation |
Multiple ways of sorting taxa are possible and determined by the by
argument.
The by
argument must be one of:
'rev' to reverse the current order
'name' (sort alphabetically by at
)
'asis' to keep current order as is
a sample name (descending abundance sorting within that sample)
summary stat. function e.g. sum
or mean
The at
argument must be "names" for sorting unique taxa,
or a rank name, for sorting at that rank.
at
is ignored when by
is "rev".
tax_sort(
data,
by = "name",
at = "names",
...,
tree_warn = TRUE,
verbose = TRUE,
trans = "identity",
use_counts = TRUE,
counts_warn = TRUE
)
data |
psExtra or phyloseq |
by |
how to sort, see description |
at |
"names" or a taxonomic rank to apply sorting method to, as specified in |
... |
used if summary function given, or pass |
tree_warn |
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! |
verbose |
passed to phyloseq_validate verbose (if TRUE: message about suspicious values in tax_table, and how to fix) |
trans |
name of transformation to apply to taxa before sorting (taxa are returned un-transformed) |
use_counts |
use count data if available, instead of transformed data |
counts_warn |
warn if count data are not available? |
Don't forget to pass na.rm = TRUE
to ...
if using a summary stat function in by
sorted phyloseq or psExtra
library(phyloseq)
data("dietswap", package = "microbiome")
dietswap
# reverse current order
dietswap %>%
tax_sort("rev") %>%
tax_table() %>%
head(30)
# sort alphabetically by a taxonomic rank (or "names" for taxa_names)
dietswap %>%
tax_sort(by = "name", at = "Phylum") %>%
tax_table() %>%
head(30)
# sequentially sorting by higher ranks
# sets tax_table in nested alphabetical order
dietswap %>%
tax_sort(at = "names") %>%
tax_sort(at = "Genus") %>%
tax_sort(at = "Family") %>%
tax_sort(at = "Phylum") %>%
tax_table() %>%
head(30)
# sort by function e.g. total sum or median abundance
dietswap %>%
tax_sort(by = sum) %>%
taxa_names() %>%
head(20)
# transform to compositional data (proportions) before sorting
# note that abundances are returned untransformed
dietswap %>%
tax_sort(by = sum, trans = "compositional") %>%
taxa_names() %>%
head(20)
# order by descending abundance in a single named sample
dietswap %>%
tax_sort(by = "Sample-1") %>%
otu_table() %>%
.[1:8, 1:4]
# sum order should always equal mean order if non-negative abundances
# don't forget to add na.rm = TRUE if you expect NAs in otu_table somehow
dietswap %>%
tax_sort(by = sum, na.rm = TRUE) %>%
taxa_names() %>%
head(20)
# if your phyloseq object has a phylogenetic tree,
# tax_sort will remove the tree, and warn you about this
# unless you disable that warning with tree_warn = FALSE
# You can sort by abundance at higher taxonomic ranks,
# without losing lower rank info
# e.g. sort (descending) by phyla abundances
dietswap %>%
tax_sort(by = sum, at = "Phylum") %>%
tax_table() %>%
head()
# You can sort by ascending abundance (or prevalence etc) by reversing after
dietswap %>%
tax_sort(by = "prev", at = "Phylum") %>%
tax_sort(by = "rev") %>%
tax_table() %>%
head()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.