Skip to contents

Counts the distinct aliquots, collection events, subjects (or other units) in every combination of two levels of a LIMS report, and draws the counts as a heatmap with ggplot2::geom_tile(): for example, the number of collection events of each sample type (columns) for each subject (rows), or the number of aliquots each subject has at each visit.

Usage

lims_heatmap(
  data,
  rows = "subject",
  cols = "sample_type",
  fill = "collection_event",
  facet = NULL,
  facet_direction = c("vertical", "horizontal"),
  date_unit = c("day", "week", "month", "quarter", "year"),
  show_counts = NULL,
  palette = "viridis",
  ...
)

Arguments

data

LIMS report(s), in any form lims_aggregate() reads (paths, a directory, data frames), or the aliquot-level output of lims_aggregate().

rows, cols

The levels (or columns) for the heatmap's rows and columns. Default: subjects by sample type.

fill

What to count in each cell. Default: collection events.

facet

Optional level (or column) to split the heatmap into panels.

facet_direction

"vertical" or "horizontal"; see Details.

date_unit

Unit to group collection dates into, when "collection_date" is used for rows, cols or facet: "day" (the default), "week" (labelled by its Monday), "month", "quarter" or "year".

show_counts

Write the count in each cell? NULL (the default) writes them when there are at most 400 cells.

palette

A viridis palette option ("viridis", "magma", "turbo", ...) for the fill scale.

...

Column arguments passed to lims_aggregate() when data is a report, e.g. subject_col = "Participant".

Value

A ggplot object, whose data holds the counts (one row per cell: facet, row, col and n).

Details

rows, cols, fill and facet take the levels of lims_aggregate():

"aliquot"

the aliquot barcode (specimen_id).

"collection_event"

a collection event: one subject, sample type and collection date.

"subject"

the subject, ordered by first collection date.

"sample_type", "collection_date", "microbial_species", "study"

as in lims_aggregate().

"visit"

the subject's 1st, 2nd, ... collection date, to line subjects up by visit rather than by calendar date.

"subject_day"

days since the subject's first collection date.

or any other column of the aliquot table (e.g. "aliquot_type"). fill sets what is counted in each cell: the number of distinct aliquots, collection events, subjects, sample types, ... (any level or column; missing values are not counted). Cells with nothing in them are drawn in light grey.

With facet, the heatmap is split into panels, stacked (facet_direction = "vertical", the default, sharing the columns) or side by side ("horizontal", sharing the rows), each showing only its own rows (or columns). For example, facet = "study" separates the studies, and rows = "collection_event", facet = "subject" gives each subject a panel of its own collection events.

Levels are ordered sensibly: subjects by their first collection date, dates and visits in time, collection events by subject and date, factor columns by their levels, and other values alphabetically, with missing values last as "(missing)".

See also

lims_aggregate() for the counts as a table, and lims_timeline().

Examples

reports <- lims_example()

# collection events of each sample type, per subject
lims_heatmap(reports)


# aliquots per subject at each visit, one panel per study
lims_heatmap(reports, cols = "visit", fill = "aliquot", facet = "study")


# subjects sampled each month, by sample type
lims_heatmap(reports, rows = "sample_type", cols = "collection_date",
             fill = "subject", date_unit = "month")


# what each specimen type was processed into, per subject
lims_heatmap(lims_example("facemdro"), rows = "sample_type",
             cols = "aliquot_type", fill = "aliquot", facet = "subject")