I’m traying to make an hypnogram and add color to the wake and sleep stages, something like this:
As you can see the lines are colored
This is an example of the data frame
df <- data.frame (
time = seq(0, 250),
state = c(rep ("AW", 20), rep ("QW",35), rep ("NR", 100), rep ("Rt", 40), rep("R", 55))
And I used this code
ggplot(data = df, aes(x=time, y= state))+
geom_step(aes(group=1))+
geom_line(aes(x=time, y= state, colour = state))+
labs (title = "Subject 1", x = "Time (s)", y= "State")+
theme_clean()
but I got this
enter image description here
And actually I want that to fill “AW” and “QW” with one color and “Rt” and “R” with another color
New contributor
Luis Angel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.