Skip to contents

Draws one row per subject and one point per sample, placed at the sample's collection day, so you can see at a glance how many samples each subject gave, and when. Each row is labelled with the subject and its number of samples.

Usage

funprofiler_timeline(
  data,
  subject = "host_subject_id",
  date = "collection_date",
  sample = "sample_id",
  site = NULL,
  color_var = "site",
  color_label = NULL,
  facet_var = NULL,
  x_axis = c("subject-day", "study-day", "calendar-day"),
  show_counts = TRUE,
  sample_noun = "samples",
  point_size = 3,
  palette = "turbo"
)

Arguments

data

A data frame with sample, subject and collection date columns.

subject

Column identifying the subject (e.g. patient or donor). Defaults to "host_subject_id", the BioSample attribute in sra2lab run tables.

date

Column with the collection date. Defaults to "collection_date".

sample

Column identifying the sample. Defaults to "sample_id", as made by funprofiler_aggregate(); use "run_accession" for an sra2lab run table.

site

Optional column with the sampling site or another sample category (e.g. "isolation_source"). With color_var = "site" (the default), points are coloured by site, with a legend; without site, each subject has its own colour.

color_var

What the point colours show:

"site" (the default)

the site column, or the subject when site is not given.

a column name

a subject feature: a column of data with one value per subject, such as treatment arm, outcome or age.

a vector

a subject feature given directly, one value per row of data (e.g. ifelse(profiles$host_subject_id %in% cases, "case", "control")).

A subject feature must have the same value in all of a subject's rows. Numeric features get a continuous colour scale, others a discrete one; missing values are grey.

color_label

Legend title for a subject feature. Defaults to the column name, tidied ("treatment_arm" becomes "Treatment arm"), or "Subject feature" for a vector.

facet_var

Optional variable to split the timeline into panels, one above the other in a single column, with one panel per value. It takes the same options as color_var: "site" for the site column (a subject sampled at several sites then has a row in each site's panel), a subject-level column of data, or a vector with one value per row of data. Each panel shows only its own subjects, and its height follows their number (with ggplot2 3.5.2 or later). Factor levels set the panel order; other values are sorted, with missing values last. NULL (the default) gives a single panel.

x_axis

What the x axis shows:

"subject-day" (the default)

days since each subject's first sample, so every subject starts at day 0. Best for comparing the spacing of samples across subjects.

"study-day"

days since the first sample in data, across all subjects, so day 0 is the study's first contact and each subject starts on the day they entered. Shows enrollment and follow-up on one scale.

"calendar-day"

calendar dates.

Can be abbreviated, e.g. "study".

show_counts

If TRUE (the default), each subject's label includes its number of samples.

sample_noun

Word for samples in the labels, e.g. "donations".

point_size

Size of the points.

palette

A viridis palette option ("turbo", "viridis", "magma", ...) for the point colours.

Value

A ggplot object. Add to or modify it as usual, and save it with ggplot2::ggsave().

Details

data is usually the output of funprofiler_aggregate() with run metadata joined (one row per sample and KO); it is reduced to one row per sample first. Any data frame with one or more rows per sample works, for example the run table from sra2lab::get_bioproject_runs(), to show every sample in a BioProject, profiled or not.

Collection dates can be Dates or text in YYYY-MM-DD, YYYY/MM/DD or MM/DD/YYYY form. Samples whose date is missing or cannot be read (for example SRA's "missing" or a bare year) are left out, with a warning.

See also

Examples

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


# every run in the BioProject, from the run table alone
runs <- read.csv(funprofiler_example("runs"))
funprofiler_timeline(runs, sample = "run_accession",
                     site = "isolation_source")


# days since the cohort's first sample: shows when subjects entered
funprofiler_timeline(runs, sample = "run_accession", x_axis = "study-day")


# calendar dates, one colour per subject
funprofiler_timeline(runs, sample = "run_accession",
                     x_axis = "calendar-day")


# colour by a subject feature, given as a vector
repeat_sampled <- c("GOL_003", "GOL_015", "GOL_016", "GOL_017", "GOL_019")
funprofiler_timeline(
  profiles,
  color_var = ifelse(profiles$host_subject_id %in% repeat_sampled,
                     "repeat", "single visit"),
  color_label = "Follow-up"
)


# one panel per site, coloured by site
funprofiler_timeline(profiles, site = "isolation_source",
                     facet_var = "site")