Skip to contents

Focused plots of the abundance of a single feature (a resistance gene, or all genes of a CARD AMR gene family, drug class or resistance mechanism) across samples, as RPKM (or another abundance) or CLR-transformed (see rgi_feature_abundance() for how it is computed).

Usage

rgi_feature_plot(
  data,
  feature,
  level = "aro_term",
  abundance = "rpkm",
  sample = "sample_id",
  subject = NULL,
  group = NULL,
  time = NULL,
  type = c("trajectory", "change", "both"),
  clr = FALSE,
  clr_level = "aro_term",
  pseudocount = NULL,
  match = c("exact", "regex", "fixed"),
  log10 = FALSE,
  label = paste(feature, collapse = ", "),
  italic = FALSE,
  palette = "turbo"
)

Arguments

data

A data frame from rgi_aggregate(), or any data frame with sample, feature and abundance columns, one row per sample and gene, with a single set of results per sample.

feature

The gene, family, drug class or mechanism to look for in level, e.g. "ErmB" or "carbapenem". With match = "exact", may be a vector of several.

level

Column to search for feature. Defaults to "aro_term". Any column works, e.g. "amr_gene_family", "drug_class" or "resistance_mechanism".

abundance

Abundance column: "rpkm" (reads per kilobase per million, the default), "relative_abundance" (% of the sample's resistance gene content) or "all_mapped_reads" (raw read counts).

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_level

Column defining the other parts of the composition for the CLR, with one value per gene. Defaults to "aro_term" (each gene).

pseudocount

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

match

How feature is matched: "exact", "regex" or "fixed"; see Details.

log10

If TRUE, show the abundance on a log10 axis (pseudo-log, so zeros are kept). Defaults to FALSE.

label

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

italic

If TRUE, label is set in italics (e.g. for a gene symbol). Defaults to FALSE.

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).

With log10 = TRUE, the abundance axis is on a log10 scale (with zeros drawn at the bottom of the axis), which suits RPKM's wide range; it is ignored with clr = TRUE and for the change plot.

See also

rgi_feature_abundance() for the values, and rgi_heatmap() for many features at once.

Examples

genes <- rgi_aggregate(rgi_example("results"),
                       metadata = rgi_example("runs"))
#> 1221 of 2469 gene detections were below `min_coverage` = 50% or `min_reads` = 0 and were left out.

# one gene by swab type
rgi_feature_plot(genes, "ErmB", group = "isolation_source",
                 italic = TRUE)


# a drug class, on a log10 axis
rgi_feature_plot(genes, "tetracycline antibiotic", level = "drug_class",
                 group = "isolation_source", log10 = TRUE,
                 label = "Tetracycline resistance")


# CLR-transformed: ErmB's share of each resistome
rgi_feature_plot(genes, "ErmB", group = "isolation_source", clr = TRUE,
                 italic = TRUE)


# repeated samples per subject, over time
rgi_feature_plot(genes, "ErmB", subject = "host_subject_id",
                 time = "collection_date", type = "both", italic = TRUE)
#> 2 subject(s) with a single sample were left out of the change plot.