periods | R Documentation |
Get a dataframe of sleep periods from a hypnogram, continuous or by stages.
periods(
hypnogram,
mode = "continuous",
stages = c("N1", "N2", "N3", "N4", "REM")
)
hypnogram |
A hypnogram dataframe. Dataframe must contain |
mode |
Period mode. |
stages |
Stages to include in periods. Defaults to 'c("N1", "N2", "N3", "N4", "REM")'. |
A dataframe of periods with their begin and stop times, duration and stages for stage mode.
library(ggplot2)
download.file(
"https://rsleep.org/data/hypnodensity.csv",
"hypnodensity.csv")
hypnodensity <- read.csv2("hypnodensity.csv")
unlink("hypnodensity.csv")
events <- hypnogram(hypnodensity)
periods_continuous <- periods(events, mode = "continuous")
ggplot(periods_continuous, aes(x=duration)) + geom_histogram(bins = 30)
periods_stages <- periods(events, mode = "stages")
ggplot(periods_stages, aes(x=event,y=duration,color=event)) + geom_boxplot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.