开发者

How to plot a range of data with time in hh:mm:ss.000 format in R?

I have a set of data 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 searching the web and couldn't find a way to set the xlim properly.

Here's an 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.


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)


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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜