tryCatch({
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()
}, error = function(e) {
print("Error executing this example, check your internet connection.")
})
Run the code above in your browser using DataLab