tax_rename | R Documentation |
Pairs classification at the given rank with a numeric ranking suffix (based on abundance or prevalence data) to automatically create informative taxa names.
tax_rename(
ps,
rank,
sort_by = sum,
transform_for_sort = "identity",
pad_digits = "auto",
sep = " ",
...
)
ps |
phyloseq object |
rank |
name of rank to use in new taxa names |
sort_by |
how to sort taxa for numbering within rank-based groups (a tax_sort option) |
transform_for_sort |
named of transformation to apply to taxa before sorting |
pad_digits |
how long should the numeric suffixes be? see details |
sep |
character to separate the rank prefixes from numeric suffixes |
... |
additional arguments passed to tax_sort |
e.g. "Bacteroides 003" for the third most abundant Bacteroides OTU or ASV.
Taxa are returned in original order, and otu_table is returned un-transformed.
pad_digits options:
"auto" –> minimum digits to have equal length numbers within groups
"max" –> minimum digits to have equal length numbers across all groups
A number: e.g.
3 –> 001, 002, ..., 042, ..., 180, ...
1 –> 1, 2, ..., 42, ..., 180, ...
phyloseq object
phyloseq::taxa_names
for accessing and manually setting names
library(phyloseq)
data("ibd", package = "microViz")
ps <- ibd %>%
tax_filter(min_prevalence = 3) %>%
tax_fix()
# show a few of the current, uninformative names
taxa_names(ps) %>% head(15)
taxa_names(ps) %>% tail(15)
# change names to genus classification plus number
psNewNames <- ps %>% tax_rename(rank = "Genus")
taxa_names(psNewNames) %>% head(15)
taxa_names(psNewNames) %>% tail(15)
# demonstrate some alternative argument settings
psNewNames2 <- ps %>% tax_rename(
rank = "Family", sort_by = prev, pad_digits = "max", sep = "-"
)
taxa_names(psNewNames2) %>% head(15)
taxa_names(psNewNames2) %>% tail(15)
ps %>%
tax_rename(rank = "Genus", pad_digits = 2) %>%
taxa_names() %>%
head(15)
# naming improvement on plots example
library(ggplot2)
library(patchwork)
# Overly aggressive OTU filtering to simplify and speed up example
psExample <- ps %>% tax_filter(min_prevalence = 0.4)
# before OTU renaming
before <- psExample %>%
ps_filter(activity == "inactive") %>%
tax_names2rank("Taxon") %>%
comp_barplot(
tax_level = "Taxon", n_taxa = 12, other_name = "Other",
merge_other = FALSE, bar_outline_colour = "grey60"
) +
coord_flip() +
ggtitle("Original taxon names :(")
# after OTU renaming
after <- psExample %>%
ps_filter(activity == "inactive") %>%
tax_rename(rank = "Genus", pad_digits = "max") %>%
tax_names2rank("Taxon") %>%
comp_barplot(
tax_level = "Taxon", n_taxa = 12, other_name = "Other",
merge_other = FALSE, bar_outline_colour = "grey60"
) +
coord_flip() +
ggtitle("New taxon names :)", "tax_rename(rank = 'Genus', sort_by = sum)")
before + after & theme(legend.text = element_text(size = 8))
# ordination example
psExample %>%
tax_rename(rank = "Genus", sort_by = sum) %>%
tax_names2rank("otu") %>%
tax_transform("clr", rank = "otu") %>%
ord_calc() %>%
ord_plot(
size = 2, colour = "ibd", shape = "circle", alpha = 0.5,
plot_taxa = 1:10,
tax_vec_length = 0.5,
tax_lab_style = tax_lab_style(
type = "text", max_angle = 90, check_overlap = TRUE,
size = 2.5, fontface = "bold"
),
tax_vec_style_all = vec_tax_all(alpha = 0.1)
) +
coord_fixed(clip = "off") +
stat_chull(aes(colour = ibd)) +
scale_colour_brewer(palette = "Dark2") +
theme(panel.grid = element_line(size = 0.1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.