Learn R Programming

rsleep (version 1.0.4)

plot_hypnogram: Draw a hypnogram with ggplot2.

Description

A hypnogram represents the stages of sleep as a function of time. plot_hypnogram() plot a hypnogram using the ggplot2 library from stages sleep in an event dataframe. REM stage is higlighted in red.

Usage

plot_hypnogram(events, labels = c("N3", "N2", "N1", "REM", "AWA"))

Value

a ggplot object.

Arguments

events

Events dataframe. Dataframe must have begin (POSIXt), end (POSIXt) and event

labels

Sleep stages labels. Defaults to c("N3","N2","N1","REM","AWA").

References

Silber MH, Ancoli-Israel S, Bonnet MH, Chokroverty S, Grigg-Damberger MM, et al. (2007). "The visual scoring of sleep in adults". Journal of Clinical Sleep Medicine. 3 (2): 121–31. PMID 17557422

Examples

Run this code
e <- data.frame(begin = as.POSIXlt(c(1536967800,1536967830,1536967860),origin = "1970-01-01"))
e$end <- as.POSIXlt(c(1536967830,1536967860,1536967890), origin = "1970-01-01")
e$event = c("N3","N3","REM")
plot_hypnogram(e)

Run the code above in your browser using DataLab