plot_day: Plot one or more days of diabetes data for a single subject

View source: R/07_plots.R

plot_dayR Documentation

Plot one or more days of diabetes data for a single subject

Description

Draws a two-panel plot per day. The upper panel shows the CGM trace over a shaded target range, with the SMBG measurements as diamonds; the lower panel shows the basal rate as a filled step area, the boluses as labelled circles and the carbohydrates as labelled boxes, headed by the insulin delivered over the whole day. Both panels share a 0-24 h axis of the local (wall-clock) time, and a legend is drawn underneath them.

Usage

plot_day(
  data,
  id = NULL,
  days = NULL,
  target = NULL,
  ylim_cgm = NULL,
  min_bolus = 0,
  units = "mg/dl",
  main = NULL
)

Arguments

data

A list with all data found for one individual (the output of parse_data) or for multiple individuals (the output of merge_all). Requires cleaned and standardized data. The data types cgm, basal, bolus, carbs and SMBG are drawn where they are present; a type that is absent or that holds no data for a day is skipped.

id

Character or numeric participant identifier, naming the individual to plot. Can be omitted if data holds the data of a single individual.

days

The day(s) to plot, as a Date or as a "YYYY-MM-DD" string. Defaults to every day with CGM data, i.e. one plot per day.

target

Numeric vector of length two with the glucose target range, drawn as a shaded band.

ylim_cgm

Numeric vector of length two with the limits of the glucose axis.

min_bolus

Numeric, the smallest bolus that is drawn in full, in units. Small correction boluses crowd the panel without adding much, and min_bolus = 1 draws everything below 1 U as a bare tick at its time, without a circle and without its value. Compared against the total of a bolus, so that a small immediate part followed by a large extended one is drawn in full. Defaults to 0, i.e. every bolus is drawn in full.

units

Character string, the units of the glucose data, either "mg/dl" or "mmol/l".

main

Character string with the plot title. Defaults to the id and the day. Note that the same title is used for every day if several are plotted.

Details

The daily totals are taken from total_basal and total_bolus where the export provides them, and are summed over the day otherwise. They therefore cover insulin that the drawn data may not, such as the basal delivered in automated mode by an Omnipod, and they are unaffected by min_bolus. A total that is not recorded at all is shown as "-". Where min_bolus leaves boluses out of the labelled circles, a note next to the totals says so.

Value

No return value, called for side effects: one plot is drawn per day.

Examples

path <- system.file("extdata", "glooko_example.zip", package = "aidR")
data <- parse_data(id = "1", paths = path)
plot_day(data, days = "2026-06-22")

# Custom target range, with boluses below 1 U drawn as ticks only
plot_day(data, days = "2026-06-22", target = c(70, 140), min_bolus = 1)

aidR documentation built on Oct. 28, 2026, 5:13 p.m.