[英]How to plot binary states time-series in R?
My data is some time-stamped binary states. 我的数据是带有时间戳的二进制状态。 Eg,
例如,
31/01/2014 00:00:04, 1
2014年1月31日00:00:04,1
31/01/2014 00:00:09, 0
31/01/2014 00:00:09,0
31/01/2014 00:00:13, 1
2014年1月31日00:00:13,1
The state will always form 1 to 0 and then from 0 to 1. 状态将始终从1到0,然后从0到1。
I want to plot a horizontal line at level 1 (y-axis), from time 00:04 to 00:09. 我想从时间00:04到00:09在级别1(y轴)上绘制一条水平线。
And plot a horizontal line at level 0 from time 00:09 to 00:13. 并从时间00:09到00:13在0级绘制一条水平线。
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 编辑:将geom_segment更改为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. plot(yourData$time, yourData$state, type="s")
绘制所需的楼梯。 Capital type="S"
does it towards the other side. 大写
type="S"
朝向另一侧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.