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
)

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

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.")
  })
#> # A tibble: 1,470 × 3
#>    begin               end                 event
#>    <dttm>              <dttm>              <fct>
#>  1 2016-01-15 22:30:30 2016-01-15 22:31:00 AWA  
#>  2 2016-01-15 22:31:00 2016-01-15 22:31:30 AWA  
#>  3 2016-01-15 22:31:30 2016-01-15 22:32:00 AWA  
#>  4 2016-01-15 22:32:00 2016-01-15 22:32:30 AWA  
#>  5 2016-01-15 22:32:30 2016-01-15 22:33:00 AWA  
#>  6 2016-01-15 22:33:00 2016-01-15 22:33:30 AWA  
#>  7 2016-01-15 22:33:30 2016-01-15 22:34:00 AWA  
#>  8 2016-01-15 22:34:00 2016-01-15 22:34:30 AWA  
#>  9 2016-01-15 22:34:30 2016-01-15 22:35:00 AWA  
#> 10 2016-01-15 22:35:00 2016-01-15 22:35:30 AWA  
#> # ℹ 1,460 more rows