4

Zoo オブジェクトの xyplot を作成する際に問題が発生しています。

簡単な例を作成しました:

z <- zoo(cbind(a=1:4,b=11:14,c=10:13,d=5:8,e=10:7,f=1:4), 1991:1994)

次のコードを使用して、マルチパネル xyplot を作成しています。

numLbl <- 4
xx <- seq(from = min(time(z)), to = max(time(z)), length.out = numLbl)
xyplot(z[,c(1,2,4,6)],scales = list(x = list(at = time (z), rot = 90)), layout = c(1,4), aspect = "fill", xlab = "",
panel = function (x,y, ...) {
    panel.abline (v = xx, col = "grey", lty = 3)
    panel.xyplot(x, y, type = "b", col = 1)
})

私がやりたいのは、このパネルの 1 つだけで y 軸を逆にすることです。関連する例を見つけました:

http://r.789695.n4.nabble.com/lattice-limits-in-reversed-order-with-relation-quot-same-quot-td2399883.html

ただし、私の例では prepanel を動作させることができません。私はラティスにかなり慣れていないので、おそらくパネル機能で何かわからないことがあります。

さらに、パネルの 1 つをヒストグラムとして取得し、他のパネルを線として取得する簡単な方法があれば、ヒントをいただければ幸いです。

どんな助けでも大歓迎です!

4

1 に答える 1

1

最初のジョブを実行する prepanel の例を次に示します。

numLbl <- 4
count <- 0
swap <- 3
xx <- seq(from = min(time(z)), to = max(time(z)), length.out = numLbl)
xyplot(z[,c(1,2,4,6)],scales = list(x = list(at = time (z), rot = 90)),
    layout = c(1,4), aspect = "fill", xlab = "",
panel = function (x,y, ...) {
    panel.abline (v = xx, col = "grey", lty = 3)
    panel.xyplot(x, y, type = "b", col = 1)
},
prepanel = function (x,y, ...) {
    count <<- count + 1

    lims <- list(xlim=c(min(x),max(x)), ylim=c(min(y),max(y)));

    if (swap == count) {
        lims[[2]] = rev(lims[[2]]);
    }
    lims;
}
)
于 2012-03-26T03:09:31.760 に答える