Renders a hypnogram using ggplot2 and the Circadia Lab colour palette.
Accepts both full AASM and coarse staging; the lane order (deepest sleep
at the bottom, Wake at the top) and colour mapping are set automatically
from the staging levels present in hypnogram.
Arguments
- hypnogram
A
hypnor_hypnogramobject as returned bynew_hypnogram()orread_hypnogram(), or any data frame with at minimumepochandstagecolumns – it will be passed throughnew_hypnogram()automatically if not already ahypnor_hypnogram. Epoch duration is read from the object'sepoch_secattribute.- style
"step"(default) or"capsule":"step"Classic clinical step-plot: one line tracing the stage at every epoch.
"capsule"Rounded-pill bars per contiguous stage run, one lane per stage.
- x_axis
"auto"(default),"time", or"hours":"auto"Uses actual clock time (from the
timecolumn) ifhypnogramcarries any non-NAtimestamps, otherwise falls back to elapsed hours since the first epoch."time"Forces clock time; errors if
timeis entirelyNA(nostart_timewas supplied tonew_hypnogram()ormrpheus::export_hypnogram())."hours"Forces elapsed hours since the first epoch, regardless of whether real timestamps are available.
- date_breaks
Only used when plotting clock time. Passed to
ggplot2::scale_x_datetime()'sdate_breaks. Default"2 hours".- cycles
Optional: the tibble returned by
compute_cycles(). When supplied, a dashed vertical line is drawn at the start of each cycle.- colours
Named character vector mapping stage labels to hex colours. Defaults to a built-in palette drawn from the Circadia Lab colours. Pass your own named vector to override.
- title
Optional plot title.
- corner_min
Only used by
style = "capsule". Maximum pill corner radius, in minutes. Runs shorter than2 * corner_minget a proportionally smaller radius (so very brief runs render as fully rounded capsule/stadium shapes rather than having oversized corners), longer runs are capped at this radius. Default9.
Examples
if (FALSE) { # \dontrun{
hyp <- read_hypnogram("night_001.csv")
plot_hypnogram(hyp)
plot_hypnogram(hyp, cycles = compute_cycles(hyp))
plot_hypnogram(hyp, x_axis = "hours")
plot_hypnogram(hyp, style = "capsule")
} # }