如何在 R 中以 hh:mm:ss.000 格式绘制一系列随时间变化的数据?
我有一组数据需要用 R 绘制(1M 行)。时间列(第 1 列)的格式为 hh:mm:ss.000。我想在一个时间范围内绘制图表,比如从 08:05:00 到 09:00:00。我该怎么做?我在网上搜索过,但找不到正确设置 xlim 的方法。
这是数据的一个简短示例。第 1 列是时间,第 2、3、4.. 列将位于 y 轴上。
07:51:19.553,10.785,0.000,0.392,1.512,1.527,1.553,1.560,2.838
08:05:00.661,-1.555,0.000,0.041,0.310,0.314,0.321,0.327,1.474
08:06:58.250,30.781,0.000,0.093,0.156,0.160,0.168,0.173,1.411
08:30:02.506,-0.002,0.000,0.052,0.120,0.123,0.132,0.137,1.361
09:05:00.997,-1.802,0.000,0.032,0.078,0.080,0.087,0.090,1.258
10:05:00.661,-1.555,0.000,0.041,0.310,0.314,0.321,0.327,1.474
预先感谢您的帮助。
I have a set of data that need to be plotted (1M rows) with R. The time column (column 1) is in hh:mm:ss.000 format. I would like to plot the graph in a time range, say from 08:05:00 to 09:00:00. How do I do it? I have searched the web and couldn't find a way to set the xlim properly.
Here's a short example of the data. Column 1 is time, Column 2, 3, 4.. will be on y axis.
07:51:19.553,10.785,0.000,0.392,1.512,1.527,1.553,1.560,2.838
08:05:00.661,-1.555,0.000,0.041,0.310,0.314,0.321,0.327,1.474
08:06:58.250,30.781,0.000,0.093,0.156,0.160,0.168,0.173,1.411
08:30:02.506,-0.002,0.000,0.052,0.120,0.123,0.132,0.137,1.361
09:05:00.997,-1.802,0.000,0.032,0.078,0.080,0.087,0.090,1.258
10:05:00.661,-1.555,0.000,0.041,0.310,0.314,0.321,0.327,1.474
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确实想要使用适当的时间序列类,例如zoo 或 xts
子集化、绘图……然后免费提供。从优秀的 zoo 文档开始,然后再切换到 xts 以获得更好的性能和子集化。
现在,一百万行太多了,因为您最终得到的数据比像素还要多——但至少这会给您一个总结数据的机会。
这是一个快速说明:
You really want to use a proper time series class such as zoo or xts
Subsetting, plotting, ... then come for free. Start with the excellent zoo documentation before maybe switching to xts for even better performance and subsetting.
Now, one million rows is too many as you end up with more data than pixels -- but at least this will give you a chance to summarize your data.
Here is a quick illustration:
要将字符向量更改为“日期和时间”对象、POSIXlt(ct) 对象、函数
strptime()
会很方便。这是一个如何完成的简短示例。To change character vector to "date & time" object, POSIXlt(ct) object, function
strptime()
will come handy. Here's a short example how it's done.