简体   繁体   English

如何在动物园对象的xyplot中仅反转一个y轴

[英]How to reverse only one y-axis in xyplot of zoo object

I am having some trouble in creating a xyplot of a zoo object. 我在创建动物园对象的xyplot时遇到了一些麻烦。

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: 我使用以下代码创建一个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. 我想做的是只在其中一个面板上反转y轴。 I have found a related example: 我找到了一个相关的例子:

http://r.789695.n4.nabble.com/lattice-limits-in-reversed-order-with-relation-quot-same-quot-td2399883.html 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! 很感谢任何形式的帮助!

Here's an example of a prepanel which does the first job: 这是第一份工作的预付款示例:

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;
}
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM