5

R の同じ画面で複数の不連続な時系列の折れ線グラフを表示できるようにしたいのですが、すべてのデータを一度に表示するのに問題があります。

require(xts)
require(xtsExtra)
df1=data.frame(a=1:30,b=3*1:30)
df1$b[2*1:15]=NA
df1A_xts=xts(df1,ISOdate(1900+1:30,1,1))
df1B_xts=xts(df1,ISOdate(1900+2*1:30,2,1))
df1_xts_merge=merge.xts(df1A_xts,df1B_xts)

もちろん、点グラフとしてプロットすると、すべて問題なく表示されます。

plot.xts(df1_xts_merge,screens=1,type="p",auto.legend=TRUE)

しかし、1 つ以上のシリーズを線としてプロットしようとすると、不連続性が原因で問題が発生します。たとえば、次のようになります。

plot.xts(df1_xts_merge,screens=1,auto.legend=TRUE)

これらの各シリーズを同じ軸セット上の連続線としてプロットするにはどうすればよいですか?

4

1 に答える 1

4

xts and zoo behave consistent with the default plotting methods:

matplot(df1_xts_merge,type="l")

default plotting via matplot

You seem to want a plot of the lines interpolated through the points in your xts object, in which case na.approx or na.spline will be helpful:

plot(na.approx(df1_xts_merge),screens=1,auto.legend=TRUE)

xtsExtra::plot.xts with na.approx

于 2012-11-29T02:29:37.027 に答える