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

发布于 2024-12-28 19:19:12 字数 963 浏览 2 评论 0原文

我在创建动物园对象的 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)
})

我想要做的是仅在其中一个面板上反转 y 轴。我找到了一个相关的示例:

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

但是我不能让预面板与我的示例一起使用。我对格子很陌生,面板功能可能有一些我不明白的地方。

此外,如果有一种简单的方法可以将其中一个面板作为直方图,将其他面板作为线条,我将非常感谢您的提示。

非常感谢任何帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2025-01-04 19:19:12

这是执行第一项工作的预面板的示例:

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

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;
}
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文