ps_calc_richness: Calculate richness estimate and add to phyloseq sample data

View source: R/ps_calc_richness.R

ps_calc_richnessR Documentation

Calculate richness estimate and add to phyloseq sample data

Description

Wrapper around microbiome::richness() function. Takes and returns a phyloseq object. Calculates a richness estimate at a given taxonomic rank. Returns phyloseq unaggregated, with an additional variable. Variable name is by default created by pasting the index and rank.

Usage

ps_calc_richness(
  ps,
  rank,
  index = "observed",
  detection = 0,
  varname = paste0(index, "_", rank)
)

Arguments

ps

phyloseq

rank

taxonomic rank name, or "unique"

index

"observed" or "chao1" - name of richness estimate from microbiome::richness()

detection

Detection threshold. Used for the "observed" index.

varname

name of the variable to be added to phyloseq sample data

Details

Don't filter taxa before calculating richness.

These richness indices are estimates. For a discussion of the uncertainty and bias of these estimates see e.g. work by Amy Willis https://doi.org/10.3389/fmicb.2019.02407

Value

phyloseq

See Also

ps_calc_diversity

microbiome::richness

Examples

data(ibd, package = "microViz")
ibd %>%
  ps_filter(abx == "abx") %>%
  tax_fix() %>%
  ps_calc_richness("Genus", index = "observed") %>%
  ps_calc_richness("Family", index = "chao1") %>%
  tax_transform(rank = "Genus", transform = "clr") %>%
  ord_calc("PCA") %>%
  ord_plot(
    colour = "observed_Genus", size = "chao1_Family"
  ) +
  ggplot2::scale_colour_viridis_c()


david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.