网格图中的 panel.rect 和对数刻度

发布于 2025-01-16 00:02:02 字数 580 浏览 2 评论 0原文

我想知道如何在网格图中绘制带有 log y 轴的突出显示矩形。我的想法是使用 panel.rect(),它可以在没有对数刻度的情况下工作:

set.seed(1)
y <- runif(100, min=1, max=1000)
x <- seq_along(y)

xyplot(y ~ x,
       panel=function(x,y,...) {
           cpl <- current.panel.limits()
           panel.rect(xleft=cpl$xlim[1], ybottom=10,
                      xright=cpl$xlim[2], ytop=500,
                      fill="lightgray", border="lightgray", alpha=.6)
           panel.xyplot(x,y,...)
           
       },
       scales=list(y=list(log=FALSE))
       )

但是,当 log=TRUE 时,矩形消失。有什么想法吗?谢谢,斯文

I'm wondering about how to draw a highlighted rectangle with log y-axis in a trellis plot. My idea was to use panel.rect(), which works without a log scale:

set.seed(1)
y <- runif(100, min=1, max=1000)
x <- seq_along(y)

xyplot(y ~ x,
       panel=function(x,y,...) {
           cpl <- current.panel.limits()
           panel.rect(xleft=cpl$xlim[1], ybottom=10,
                      xright=cpl$xlim[2], ytop=500,
                      fill="lightgray", border="lightgray", alpha=.6)
           panel.xyplot(x,y,...)
           
       },
       scales=list(y=list(log=FALSE))
       )

However, when log=TRUE, the rectangle disappears. Are there any ideas? Thanks, Sven

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

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

发布评论

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

评论(1

萧瑟寒风 2025-01-23 00:02:02

好的,这样就可以了,首先转换 panel.rect() 的 y 坐标:

xyplot(y ~ x, 
       panel=function(x,y, ...) {
           cpl <- current.panel.limits()
           yseq <- log(c(100,1000))
           panel.rect(xleft=cpl$xlim[1],
                      ybottom=yseq[1],
                      xright=cpl$xlim[2],
                      ytop=yseq[2],
                      fill="lightgray", border="lightgray", alpha=.6)
           panel.xyplot(x,y,...)
       },
       scales=list(y=list(log=2))
       ) 

ok, this do the trick, first transform the y-coordinates for panel.rect():

xyplot(y ~ x, 
       panel=function(x,y, ...) {
           cpl <- current.panel.limits()
           yseq <- log(c(100,1000))
           panel.rect(xleft=cpl$xlim[1],
                      ybottom=yseq[1],
                      xright=cpl$xlim[2],
                      ytop=yseq[2],
                      fill="lightgray", border="lightgray", alpha=.6)
           panel.xyplot(x,y,...)
       },
       scales=list(y=list(log=2))
       ) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文