网格图中的 panel.rect 和对数刻度
我想知道如何在网格图中绘制带有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这样就可以了,首先转换 panel.rect() 的 y 坐标:
ok, this do the trick, first transform the y-coordinates for panel.rect():