hypnogram: Filter and reorder an events dataframe or a hypnodensity to...

View source: R/events.R

hypnogramR Documentation

Filter and reorder an events dataframe or a hypnodensity to keep only sleep stages related-events.

Description

Remove non-sleep stages events and reorder dataframe rows using the begin column.

Usage

hypnogram(
  events,
  labels = c("N3", "N2", "N1", "REM", "AWA"),
  startTime = 946681200,
  epoch_duration = 30,
  plot = FALSE
)

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").

startTime

Hypnogram start time. Used when a hypnodensity dataframe is passed as events. Defaults to 946681200.

epoch_duration

Epoch duration in seconds. Used when a hypnodensity dataframe is passed as events. Defaults to 30.

plot

Plot the hypnogram or in not using ggplot2.

Value

Hypnogram dataframe or plot.

Examples

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)

rsleep documentation built on Nov. 6, 2023, 1:06 a.m.