lims_heatmap() counts the aliquots, collection events,
subjects (or other units) in every combination of two levels of a LIMS
report, and draws the counts as a heatmap: what was collected from whom,
when, and how much of it is in the freezer. It takes the same inputs as
lims_aggregate() (see
vignette("lims-aggregate")). The examples use the two
reports installed with lims2sra (see ?lims_example).
Rows, columns and fill
Three arguments set the heatmap: rows and
cols (the levels to cross) and fill (what to
count in each cell). Each takes a level:
| level | |
|---|---|
"aliquot" |
the aliquot barcode |
"collection_event" |
one subject, sample type and collection date |
"subject" |
ordered by first collection |
"sample_type", "collection_date",
"microbial_species", "study"
|
|
"visit" |
the subject’s 1st, 2nd, … collection date |
"subject_day" |
days since the subject’s first collection |
or any other column of the aliquot table, such as
"aliquot_type" or "status".
By default, rows are subjects, columns are sample types, and each cell counts collection events: how many times each sample type was collected from each subject.
library(lims2sra)
gol <- lims_example("gol")
lims_heatmap(gol)
Empty cells (nothing collected) are light grey: some GOL visits had
no stool swab. The count is written in each cell when there are at most
400 cells; set show_counts to choose.
Counting other units
Change cols and fill to count aliquots at
each visit, to see how much material each visit left:
lims_heatmap(gol, cols = "visit", fill = "aliquot")
or count subjects, here per sample type and calendar month
(date_unit groups collection dates into weeks, months,
quarters or years), to see enrolment over time:
lims_heatmap(gol, rows = "sample_type", cols = "collection_date",
fill = "subject", date_unit = "month")
Any column works: the status column shows how many
aliquots of each type are still in circulation, and how many were
disposed of:
lims_heatmap(gol, rows = "sample_type", cols = "status", fill = "aliquot")
In FACEMDRO, swabs were cultured and isolates picked from the
cultures. Crossing sample_type (the specimen collected)
with aliquot_type (what each aliquot is) shows what each
specimen type was processed into:
facemdro <- lims_example("facemdro")
lims_heatmap(facemdro, rows = "sample_type", cols = "aliquot_type",
fill = "aliquot")
Environmental swabs led to by far the most cultures. The diagonal is the specimens themselves.
Panels
facet splits the heatmap into panels. By default they
are stacked and share the columns, and each panel shows only its own
rows. Both studies, one panel each, counting the subjects sampled each
month:
lims_heatmap(lims_example(), rows = "sample_type", cols = "collection_date",
fill = "subject", date_unit = "month", facet = "study")
FACEMDRO enrolled one or two subjects at a time; GOL enrolled most of its subjects in early 2026. Or one panel per FACEMDRO subject, counting the aliquots (specimens, cultures and isolates) of each sample type at each visit:
lims_heatmap(facemdro, rows = "sample_type", cols = "visit",
fill = "aliquot", facet = "subject", show_counts = FALSE)
Every subject was swabbed at nearly every visit, but the environmental swabs of some visits were cultured far more than others.
facet_direction = "horizontal" places the panels side by
side, sharing the rows, e.g. one panel per sample type:
lims_heatmap(gol, cols = "visit", fill = "aliquot",
facet = "sample_type", facet_direction = "horizontal")
Isolate species
For reports with species, "microbial_species" works like
any other level. Keep only the aliquots with a species (and drop the
“DUPLICATE” notes; see vignette("lims-aggregate")) to see
which species were isolated from each subject:
fac <- lims_aggregate(facemdro)
isolates <- fac[!is.na(fac$microbial_species) &
fac$microbial_species != "DUPLICATE", ]
lims_heatmap(isolates, cols = "microbial_species", fill = "aliquot")
The counts
The counts behind the plot are in its data, one row per
cell (n is NA for empty cells):
p <- lims_heatmap(gol)
head(p$data)
#> # A tibble: 6 × 5
#> facet row col n text_colour
#> <fct> <fct> <fct> <int> <chr>
#> 1 all GOL_027 Axilla Swab 5 black
#> 2 all GOL_027 Groin Swab 4 white
#> 3 all GOL_027 Perirectal Swab 4 white
#> 4 all GOL_027 Stool Swab 2 white
#> 5 all GOL_025 Axilla Swab 5 black
#> 6 all GOL_025 Groin Swab 5 blackFor the same counts as a table, use lims_aggregate(),
e.g.
lims_aggregate(gol, by = c("subject", "sample_type")).