如何在 R 中以 hh:mm:ss.000 格式绘制一系列随时间变化的数据?

发布于 2024-09-11 15:12:01 字数 612 浏览 3 评论 0原文

我有一组数据需要用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何止钟意 2024-09-18 15:12:01

确实想要使用适当的时间序列类,例如zoo 或 xts

子集化、绘图……然后免费提供。从优秀的 zoo 文档开始,然后再切换到 xts 以获得更好的性能和子集化。

现在,一百万行太多了,因为您最终得到的数据比像素还要多——但至少这会给您一个总结数据的机会。

这是一个快速说明:

> options(digits.sec=3)      ## important: turn on milli-sec via print()
> library(xts)
Loading required package: zoo
> X <- xts(cumsum(rnorm(100)), order.by=Sys.time()+cumsum(runif(100)/10))
> plot(X)

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:

> options(digits.sec=3)      ## important: turn on milli-sec via print()
> library(xts)
Loading required package: zoo
> X <- xts(cumsum(rnorm(100)), order.by=Sys.time()+cumsum(runif(100)/10))
> plot(X)
情定在深秋 2024-09-18 15:12:01

要将字符向量更改为“日期和时间”对象、POSIXlt(ct) 对象、函数 strptime() 会很方便。这是一个如何完成的简短示例。

dtm <-  strptime(c("1.1.2010 11:35"), format =  "%d.%m.%Y %H:%M", tz = "CET")

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.

dtm <-  strptime(c("1.1.2010 11:35"), format =  "%d.%m.%Y %H:%M", tz = "CET")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文