Plot a double-plotted actogram with activity bars
Source:R/plot_actogram.R
plot_actogram_activity.RdSame double-plot layout as plot_actogram_double() — each day appears in
both the left and right column of adjacent rows — but each epoch is rendered
as a vertical bar whose height is proportional to the raw activity count
(default: ZCMn, the zero-crossing mean from ActTrust). Bars are coloured
by sleep/wake state, so the plot simultaneously conveys activity intensity
and state classification.
Usage
plot_actogram_activity(
result,
tz = NULL,
title = NULL,
colours = NULL,
activity_col = "ZCMn",
activity_cap_quantile = 0.99,
log_scale = FALSE,
date_label_every = 7L,
epoch_min = 1,
base_size = 13
)Arguments
- result
A
zeitr_resultlist (fromrun_pipeline()orrun_pipeline_native()), or a tibble with at leastdatetimeandstatecolumns.- tz
character(1)orNULL. Timezone for date and time-of-day extraction.NULL(default) auto-detects from the timezone attribute embedded in thedatetimePOSIXct column; falls back to"UTC"when absent.- title
character(1)orNULL. Plot title.NULLconstructs"Actogram \u2014 <subject_id>"fromresult$subject_idwhen available.- colours
Named character vector mapping state labels (
"wake","sleep","nap","off-wrist") to hex colours.NULLusesactogram_colours().- activity_col
character(1). Name of the column inresult$datato use as the activity signal. Default"ZCMn"(zero-crossing mean; present in all ActTrust recordings processed byzeitR).- activity_cap_quantile
numeric(1)in (0, 1]. Quantile of non-zero activity values used to cap bar heights before normalising. Default0.99(top 1 % of active epochs are clipped to full bar height).- log_scale
logical(1). IfTRUE, applies alog1p()transform to the activity signal before capping and normalising, compressing the dynamic range so lower-activity variation is easier to see. DefaultFALSE(linear scale).- date_label_every
integer(1). Label every Nth row on the y-axis. Default7(weekly ticks).- epoch_min
numeric(1). Epoch duration in minutes. Used as the tile width inggplot2::geom_tile(). Default1(ActTrust standard).- base_size
numeric(1). Base font size passed toggplot2::theme_minimal(). Default13.
Details
Bar heights are capped at the activity_cap_quantile quantile of
non-zero epochs to prevent outlier activity bursts from compressing the
visible range for the rest of the recording. A thin baseline stub
(2 % of row height) is drawn for zero-activity epochs so that sleep periods
and off-wrist blocks remain faintly visible.
Actigraphy activity counts are typically right-skewed, with occasional
bursts far above the typical waking level. On the default linear scale
this compresses most of the meaningful variation among low-to-moderate
activity epochs into a thin sliver near the baseline. Set log_scale = TRUE to apply a log1p() transform (log(1 + x), so zero-activity
epochs map to 0 rather than -Inf) before capping and normalising –
this expands the low-activity range at the cost of visually compressing
the difference between already-high activity bursts.
Examples
if (FALSE) { # \dontrun{
result <- run_pipeline("recordings/P001.txt", tz = "America/Sao_Paulo")
plot_actogram_activity(result)
# Cap at 95th percentile to highlight moderate activity
plot_actogram_activity(result, activity_cap_quantile = 0.95)
# Log scale: reveals structure among low-activity epochs that a linear
# scale would otherwise compress near the baseline
plot_actogram_activity(result, log_scale = TRUE)
} # }