How well was a cohort sampled? lims_timeline() draws one
row per subject and one point per collection event, at the day it was
collected, so you can see at a glance how many times each subject was
sampled, how regularly, and with which sample types. It takes the same
inputs as lims_aggregate() (see
vignette("lims-aggregate")): one or more LIMS reports, or
the aliquot table lims_aggregate() makes. The examples use
the two reports installed with lims2sra (see
?lims_example).
Collection events
library(lims2sra)
lims_timeline(lims_example("gol"))
Each point is a collection event: one sample type collected from one subject on one day, however many aliquots it was split into. Events on the same day (here, the four swabs taken at each visit) are spread out vertically so that none is hidden. Each subject’s row is labelled with its number of collection events, subjects are ordered by their first collection, and by default the x axis is days since that subject’s first collection: most GOL subjects were swabbed weekly for a month, and some were followed for three months.
The x axis
x_axis = "study-day" counts days from the first
collection in the data, so subjects start on the day they entered;
"calendar-day" shows dates:
lims_timeline(lims_example("gol"), x_axis = "calendar-day")
Aliquots
In FACEMDRO, one swab can be split into many cultures and isolates.
size_by_aliquots = TRUE scales each point by its number of
aliquots, showing which collections were processed most:
lims_timeline(lims_example("facemdro"), size_by_aliquots = TRUE)
The dark points at day 0 are isolates whose source specimen is not in the LIMS: they have “Bacterial Cell Iso” as their sample type, and were collected weeks to months before the study swabs.
Or draw every aliquot, with unit = "aliquot"; each
subject’s label then counts aliquots. Here for the throat swabs only,
coloured by what each aliquot is:
fac <- lims_aggregate(lims_example("facemdro"))
lims_timeline(fac[fac$sample_type == "Throat Swab", ], unit = "aliquot",
color_var = "aliquot_type")
Colours, shapes and panels
color_var, shape_var and
facet_var each take a level or column of the aliquot table:
"sample_type", "aliquot_type",
"microbial_species", "study", or any other
column, such as a subject feature you have joined to the report. Here
both studies are drawn, each in its own panel sized to its subjects,
with shapes showing which collection events were cultured:
both <- lims_aggregate(lims_example())
both$processing <- ifelse(
both$aliquot_type %in% c("Bacterial Culture", "Bacterial Cell Iso",
"Cells"),
"Culture or isolate", "Specimen"
)
lims_timeline(both, facet_var = "study", shape_var = "processing")
A collection event whose aliquots differ in the variable shown (here, a swab and the cultures grown from it) is drawn as one point for each value.
Isolate species
With color_var = "microbial_species", aliquots with a
species are coloured by it, and the rest are grey. In FACEMDRO only a
few isolates have a species, so keep just those (removing the
“DUPLICATE” notes typed into the species field; see
vignette("lims-aggregate")) to see when each organism was
isolated, and from whom:
fac$microbial_species[fac$microbial_species == "DUPLICATE"] <- NA
lims_timeline(fac[!is.na(fac$microbial_species), ], unit = "aliquot",
color_var = "microbial_species", x_axis = "calendar-day")
A report with no species data (such as GOL) gives an error rather than an empty legend.
Subject features
Join anything you know about the subjects to the aliquot table and colour or split by it, for example from a table of clinical data:
clinical <- read.csv("clinical.csv") # one row per subject_id
gol <- lims_aggregate(lims_example("gol"))
gol <- merge(gol, clinical, by = "subject_id", all.x = TRUE)
lims_timeline(gol, color_var = "age") # numeric: a continuous scale
lims_timeline(gol, facet_var = "treatment_arm")color_var = NULL gives each subject its own colour, with
no legend.
Customizing
lims_timeline() returns a ggplot, so you can add to it
and save it as usual:
lims_timeline(lims_example("gol")) +
ggplot2::labs(title = "GOL sampling") +
ggplot2::geom_vline(xintercept = 28, linetype = "dashed")
ggplot2::ggsave("timeline.pdf", width = 8, height = 6)