Learn R Programming

rsleep (version 1.0.12)

hypnogram: 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
)

Value

Hypnogram dataframe or plot.

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.

Examples

Run this code
tryCatch({
  fpath <- paste0(tempdir(),"/15012016HD.csv")

  download.file("https://rsleep.org/data/15012016HD.csv",fpath, method="curl")

  events <- read_events_noxturnal(fpath)

  unlink(fpath)

  hypnogram(events)
 }, error = function(e) {
  print("Error executing this example, check your internet connection.")
  })

Run the code above in your browser using DataLab