4

I am having some trouble in creating a xyplot of a zoo object.

I have created a simplified example:

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

I am using the following code to create a multipanel 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)
})

What I would like to do is the reverse the y-axis on only one of this panels. I have found a related example:

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

However I cannot get the prepanel to work with my example. I am quite new to lattice, and there is probably something with the panel function I do not understand.

In addition if there is an easy way to get one of the panels as histograms and the others as lines I would be very grateful for tips.

Any help is very much appreciated!

4

1 回答 1

1

这是完成第一项工作的预面板示例:

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 回答