简体   繁体   English

每毫秒绘制时间序列

[英]Plot time series per millisecond

I can't get my plot to show the points per millisecond.我无法让我的图显示每毫秒的点数。 It always aggregates it all together per second.它总是每秒将它们聚合在一起。 But I have data per millisecond.但我每毫秒都有数据。 What am I doing wrong?我究竟做错了什么?

I have a data frame with:我有一个数据框:

                   time     x      y    z
2015-09-24 14:21:40.130  0.11  -0.19 1.54
2015-09-24 14:21:40.229  0.11  -0.19 1.54
2015-09-24 14:21:40.279  1.27  -0.55 1.69
2015-09-24 14:21:40.309  0.19   0.05 0.44
2015-09-24 14:21:40.342  1.15  -0.16 1.39
2015-09-24 14:21:40.426  0.03   0.88 0.12

The time column is POSIXct time时间列是POSIXct时间

options(digits.secs=3)
data$time <- as.POSIXct(data$time, "%H:%M:%OS" ,tz = "GMT")

When I plot it plot(data$time, data$z) it takes all the points in one second and plots that on the same line.当我绘制plot(data$time, data$z)它会在一秒钟内获取所有点并将其绘制在同一条线上。 So if I plot only 4 seconds of the data frame it shows 4 stripes of points instead of a continuous distribution of the milliseconds it contains between the seconds.因此,如果我只绘制 4 秒的数据帧,它会显示 4 条点,而不是它在秒之间包含的毫秒数的连续分布。

I would like to see the points distributed in milliseconds.我想查看以毫秒为单位分布的点数。 I also tried ggplot but there it is the same.我也试过ggplot但它是一样的。 Hopefully my question is a bit clear, for I can't post any image.希望我的问题有点清楚,因为我不能发布任何图片。

for image see: https://github.com/NieneB/rplot/blob/master/Rplot01.png图片见: https : //github.com/NieneB/rplot/blob/master/Rplot01.png

Part of the problem is scale.部分问题在于规模。 Millisecond differences aren't well separated when your scale covers minutes of data.当您的规模涵盖几分钟的数据时,毫秒差异无法很好地分离。 I've expanded your sample to include four data sets separated by several minutes and where each set lies within the same second as is suggested by the chart you reference in your link.我已经扩展了您的样本,以包含四个数据集,这些数据集间隔几分钟,并且每个数据集都位于您在链接中引用的图表所建议的同一秒内。 ggplot could be used to plot this as shown in the following: ggplot可用于绘制此图,如下所示:

library(ggplot2)
sp <- ggplot(cbind(data, DayHrMin=format(data$time,"%Y-%m-%d %H:%M:%S")), 
             aes(x=as.POSIXlt(time)$sec, y=z))
sp <- sp + geom_point()
sp <- sp + facet_wrap( ~ DayHrMin, scale="free_x")
plot(sp)

This generates the following chart:这将生成以下图表:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM