My data is some time-stamped binary states. Eg,
31/01/2014 00:00:04, 1
31/01/2014 00:00:09, 0
31/01/2014 00:00:13, 1
The state will always form 1 to 0 and then from 0 to 1.
I want to plot a horizontal line at level 1 (y-axis), from time 00:04 to 00:09.
And plot a horizontal line at level 0 from time 00:09 to 00:13.
A vertical line shall be at the time of transaction.
Is there any way to plot this?
Thanks.
EDIT: changed geom_segment to geom_step
# data
a <- as.POSIXct(Sys.time())
mydf <- data.frame(time=seq(a,a+50,by=10),state=0:1)
library(ggplot2)
ggplot(mydf) + geom_step( aes(x=time , y=state ))
plot(yourData$time, yourData$state, type="s")
plots the stairs you want. Capital type="S"
does it towards the other side.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.