2

我有多个时间序列对象,覆盖不同的时间段,数据中有间隙,频率不同(一些每小时数据,一些 15 分钟,一些 1 分钟)。

我正在尝试在 xy 散点图中相互绘制不同的时间序列对象 - 看看是否存在明显的相关性,并使用 ggplot 制作“漂亮”的图以进行演示。显然,只能在数据存在的地方同时绘制/比较x数据y

我能够获得带有基本图形的快速图形,但想要更漂亮的东西。

例如,这适用于基础 R:

require(zoo)
x <- zoo(sort(rnorm(10)),as.POSIXct("2013/07/26")+1:10)
y <- zoo(sort(rnorm(30)),as.POSIXct("2013/07/26")+(1:30)/2)
plot(x,y)

并尝试对 ggplot 做同样的事情失败:

data <- rbind(melt(fortify(x),id="Index"),melt(fortify(y),id="Index"))
ggplot(data,aes(x=x,y=y))+geom_point()
Don't know how to automatically pick scale for object of type zoo. Defaulting to continuous
Don't know how to automatically pick scale for object of type zoo. Defaulting to continuous
Error: Aesthetics must either be length one, or the same length as the dataProblems:x

欢迎对更好的标题/描述提出建议

4

1 回答 1

3

那这个呢:

aaa<-merge(x,y, all=FALSE)
ggplot(aaa,aes(x=x,y=y))+geom_point()    ?
于 2013-07-26T17:07:29.907 回答