如何使用 scatterplot/xyplot 和 POSIX 时间对象创建多面板图?
一个新手问题。 (添加新信息)
我有一组随机收集的带时间戳的数据。我喜欢创建绘图矩阵,但无法使用散点图或 xyplot & 进行创建。时间对象。
我的数据
dataset$Time #POSIX time objects (no set sampling period)
#i built POSIX time objects by dataset$Time<-strptime(tt, "%H:%M:%OS")
#the origial string was formated like this 12:12:12.234 (HH:MM:SS:msec)
dataset$d1, dataset$d2 #integers
dataset$d3 #factor with 10 levels
。
我可以做到这些
plot( dataset$Time, dataset$d1)
scatterplot(dataset$d1 ~ dataset$d2 | dataset$d3, data=dataset)
xyplot(dataset$d1 ~ dataset$d2 | dataset$d3, data=dataset)
但是,我不能做到这些(x 轴中的 POSIX 时间对象)
scatterplot(dataset$d1 ~ dataset$Time | dataset$d3, data=dataset)
xyplot(dataset$d1 ~ dataset$Time | dataset$d3, data=dataset)
(新信息)
结构错误(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"),:无效的“x”参数。
(新信息)但是这个 与(y 轴中的 POSIX 时间对象)
xyplot(dataset$Time ~ dataset$d1 | dataset$d3, data=dataset)
相关,但不同的问题是 hexbin。当时间对象添加到 hexbin 时,hexbin 中的图在单位上不显示正确的时间格式,
bin<-hexbin(dataset$Time, dataset$d1)
plot(bin))
该怎么办?
我 它!!
A newbie question. (ADDED NEW INFO)
I have a set of time stamped data that were collected randomly. I like to create a matrix of plots, but I could not create using either scatterplot or xyplot & time objects.
my data
dataset$Time #POSIX time objects (no set sampling period)
#i built POSIX time objects by dataset$Time<-strptime(tt, "%H:%M:%OS")
#the origial string was formated like this 12:12:12.234 (HH:MM:SS:msec)
dataset$d1, dataset$d2 #integers
dataset$d3 #factor with 10 levels
.
i can do these
plot( dataset$Time, dataset$d1)
scatterplot(dataset$d1 ~ dataset$d2 | dataset$d3, data=dataset)
xyplot(dataset$d1 ~ dataset$d2 | dataset$d3, data=dataset)
However, i can NOT do these (POSIX time object in x-axis)
scatterplot(dataset$d1 ~ dataset$Time | dataset$d3, data=dataset)
xyplot(dataset$d1 ~ dataset$Time | dataset$d3, data=dataset)
(NEW INFO)
Error in structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt", "POSIXct"), : invalid 'x' argument.
(NEW INFO) but this works (POSIX time object in y-axis)
xyplot(dataset$Time ~ dataset$d1 | dataset$d3, data=dataset)
related, but different question is hexbin. When time objects are added to hexbin, the plot from the hexbin does not show correct time format on the units.
bin<-hexbin(dataset$Time, dataset$d1)
plot(bin))
What should I do?
Thanks for looking into it!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个工作示例。您可能弄错了数据格式——需要注意精确的数据格式。
首先,一个简单的数据框:
这是所谓的宽形式,格子不使用。您需要将其转换为长格式。我在这里使用
stack()
,您也可以使用 重塑包:
现在 xyplot 调用很简单:
您当然可以使用更复杂的条件表达式。
Here is a working example. You may have gotten your data formats wrong -- one needs to be careful about the precise data formats.
First, a simple data frame:
This is so-called wide form which lattice does not use. You need to transform it into long format. I use
stack()
here, you can also usecast()
andmelt()
from the reshapepackage:
Now the
xyplot
call is simply:and you can of course use much more complicated conditioning expressions.
显然 R 在处理 POSIX 时代的成瘾问题时遇到了一些问题......它给了我错误:
只需将它们转换为数字,它应该工作。您可以隐藏相应的轴并稍后使用正确的日期重新绘制
,例如:
Apparently R has some problem dealing with addiction of POSIX times... it gives me the error:
just cast them to numeric and it should work. You can hide the corresponding axis and redraw it later with the correct dates
E.g.:
对我来说它只是有效,所以你可能有一个格式错误的时间向量。当你调用
class(dataset$Time)
时你会得到什么?它应该包含“POSIXct”才能正常工作。另一方面,如果您提供
data=dataset
,则无需将dataset$
放入公式中。For me it just works, so you probably has a time vector in a bad format. What do you get when you call
class(dataset$Time)
? It should contain "POSIXct" for this to work.On the other hand, you don't need to put
dataset$
in formula if you supplydata=dataset
.