Skip to contents

Focused plots of the abundance of a single function (a KO, or all KOs of a KEGG pathway or class) across samples, as relative abundance (%) or CLR-transformed (see funprofiler_feature_abundance() for how it is computed).

Usage

funprofiler_feature_plot(
  data,
  feature,
  level = "ko",
  abundance = "relative_abundance",
  sample = "sample_id",
  subject = NULL,
  group = NULL,
  time = NULL,
  type = c("trajectory", "change", "both"),
  clr = FALSE,
  clr_level = "ko",
  pseudocount = NULL,
  fixed = FALSE,
  label = feature,
  italic = FALSE,
  palette = "turbo"
)

Arguments

data

A data frame from funprofiler_aggregate(), or any data frame with sample, feature and abundance columns, one row per sample and KO, with a single profile per sample.

feature

Text (a regular expression unless fixed = TRUE) to look for in level, e.g. "K01990" or "beta-Lactam resistance".

level

Column to search for feature. Defaults to "ko". Any column works, e.g. "pathway", "pathway_class", "ko_name" or "ko_symbol".

abundance

Abundance column: "relative_abundance" (%, the default) or "abundance" (proportion).

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 KO. Defaults to "ko" (each KO).

pseudocount

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

fixed

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

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

See also

funprofiler_feature_abundance() for the values, and funprofiler_heatmap() for many features at once.

Examples

profiles <- funprofiler_aggregate(funprofiler_example("profiles"),
                                  metadata = funprofiler_example("runs"))

# one KO by swab type
funprofiler_feature_plot(profiles, "K01990", group = "isolation_source",
                         label = "K01990 (ABC-2 transporter ATPase)")


# CLR-transformed
funprofiler_feature_plot(profiles, "K01990", group = "isolation_source",
                         clr = TRUE)


# repeated samples per subject, over time
funprofiler_feature_plot(profiles, "K01990",
                         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{
# a KEGG pathway, with annotation from funprofiler_kegg()
profiles <- funprofiler_aggregate(
  funprofiler_example("profiles"), metadata = funprofiler_example("runs"),
  kegg = funprofiler_kegg("data/kegg/ko00001.keg")
)
funprofiler_feature_plot(profiles, "beta-Lactam resistance",
                         level = "pathway", subject = "host_subject_id",
                         time = "collection_date", clr = TRUE,
                         type = "both")
} # }