R/events.R
hypnogram.Rd
Remove non-sleep stages events and reorder dataframe rows using the begin
column.
hypnogram(
events,
labels = c("N3", "N2", "N1", "REM", "AWA"),
startTime = 946681200,
epoch_duration = 30,
plot = FALSE
)
Events dataframe. Dataframe must have begin
(POSIXt
), end
(POSIXt
) and event
Sleep stages labels. Defaults to c("N3","N2","N1","REM","AWA")
.
Hypnogram start time. Used when a hypnodensity dataframe is passed as events. Defaults to 946681200.
Epoch duration in seconds. Used when a hypnodensity dataframe is passed as events. Defaults to 30.
Plot the hypnogram or in not using ggplot2
.
Hypnogram dataframe or plot.
fpath <- paste0(tempdir(),"SC4001EC-Hypnogram.edf")
furl <- paste0("https://www.physionet.org/files/sleep-edfx/1.0.0/",
"sleep-cassette/SC4001EC-Hypnogram.edf?download")
download.file(furl,fpath)
events <- read_events_sleepedfx(fpath)
unlink(fpath)
hypnogram(events, plot = TRUE)