Skip to contents

Focused plots of the abundance of a single taxon (for example Clostridioides difficile) across samples, as raw relative abundance (%) or CLR-transformed (see sylph_taxon_abundance() for how it is computed).

Usage

sylph_taxon_plot(
  data,
  taxon,
  rank = "species",
  abundance = "taxonomic_abundance",
  sample = "sample_id",
  subject = NULL,
  group = NULL,
  time = NULL,
  type = c("trajectory", "change", "both"),
  clr = FALSE,
  clr_rank = "accession",
  pseudocount = NULL,
  fixed = FALSE,
  taxon_label = taxon,
  italic = TRUE,
  palette = "turbo"
)

Arguments

data

A data frame from sylph_aggregate(), or any data frame with sample, taxon and abundance columns, one row per sample and genome.

taxon

Text (a regular expression unless fixed = TRUE) to look for in rank, e.g. "Clostridioides difficile".

rank

Column to search for taxon. Defaults to "species". Any column works, e.g. "genus", "organism", "gtdb_taxonomy" or "contig_name".

abundance

Abundance column: "taxonomic_abundance" (the default) or "sequence_abundance".

sample

Column identifying the sample. Defaults to "sample_id".

subject

Optional column identifying the subject, to link a subject's repeated samples.

group

Optional column of subject or sample groups (e.g. cases and controls, or sampling sites), for colours and panels.

time

Optional column giving each sample's time (a Date, date text, or number), used to order and place a subject's samples.

type

With subject: "trajectory", "change" or "both". Ignored without subject.

clr

If TRUE, also return the CLR-transformed abundance; see Details.

clr_rank

Column defining the other features of the composition for the CLR. Defaults to "accession" (each genome).

pseudocount

Value that replaces zeros before the CLR. Defaults to half the smallest non-zero abundance in data.

fixed

If TRUE, match taxon exactly as written (case-sensitive, not a regular expression).

taxon_label

Name of the taxon for the axis title. Defaults to taxon.

italic

If TRUE (the default), taxon_label is set in italics.

palette

A viridis palette option for the group colours.

Value

A ggplot object (for type = "both", a patchwork object). The per-sample values are in the data element of the (first) plot.

Details

What is drawn depends on whether repeated samples are linked by subject:

Without subject

a box plot of the samples' abundance in each group (or all together), with the samples as points.

With subject, type = "trajectory"

each subject's samples joined by a line, in order. The x axis is time (a date or number, e.g. days since first sample) when given, otherwise the sample's position in the subject's series ("Sample 1", "Sample 2", ...), ordered by time or else by sample. With group, one panel per group.

With subject, type = "change"

the change in abundance from each subject's first to last sample, per group. Subjects with a single sample are left out.

With subject, type = "both"

the trajectory and change plots side by side (combined with patchwork).

See also

sylph_taxon_abundance() for the values, and sylph_heatmap() for many taxa at once.

Examples

profiles <- sylph_aggregate(sylph_example("profiles"),
                            metadata = sylph_example("runs"))

# Staphylococcus epidermidis by swab type
sylph_taxon_plot(profiles, "Staphylococcus epidermidis",
                 group = "isolation_source")


# CLR-transformed, genus level
sylph_taxon_plot(profiles, "Escherichia", rank = "genus", clr = TRUE,
                 group = "isolation_source")


# repeated samples per subject, over time
sylph_taxon_plot(profiles, "Staphylococcus", rank = "genus",
                 subject = "host_subject_id", time = "collection_date",
                 type = "both")
#> 2 subject(s) with a single sample were left out of the change plot.


if (FALSE) { # \dontrun{
# recurrent vs cleared C. difficile infection, two tests per subject
sylph_taxon_plot(profiles, "Clostridioides difficile",
                 subject = "rcdi_subject_id", group = "subject_category",
                 time = "collection_date", clr = TRUE, type = "both")
} # }