在 xyplot 中的特定值上绘制网格线

发布于 2024-11-07 04:37:21 字数 50 浏览 4 评论 0原文

我有一个 xyplot,我想在 0 值上绘制网格线。

如何做到这一点?

I have a xyplot and I want to draw grid lines on the 0 values.

How this can be done?

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

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

发布评论

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

评论(3

塔塔猫 2024-11-14 04:37:21

根据 lattice 变更日志

晶格变化0.19
=======================

o 在 panel.xyplot() 中添加了新参数 'grid''abline'

所以你可以用一行来完成:

require(lattice)
X <- data.frame(xx=runif(20), yy=rnorm(20))

xyplot(yy~xx, X, abline=list(h=0))

Lattice graph with added line

如果你想要 panel.grid 喜欢线条样式,那么不错的技巧:

xyplot(yy~xx, X, abline=c(list(h=0),trellis.par.get("reference.line")))

带有添加漂亮样式线条的格子图

According to lattice changelog:

Changes in lattice 0.19
=======================

o Added new arguments 'grid' and 'abline' in panel.xyplot().

So you could do it in one line:

require(lattice)
X <- data.frame(xx=runif(20), yy=rnorm(20))

xyplot(yy~xx, X, abline=list(h=0))

Lattice graph with added line

If you want panel.grid like line style, then nice trick:

xyplot(yy~xx, X, abline=c(list(h=0),trellis.par.get("reference.line")))

Lattice graph with added nice style line

天荒地未老 2024-11-14 04:37:21

如果您使用lattice包(xyplot隐含),您可以使用panel.abline在标记的刻度上绘制线条。

my.df <- data.frame(a = runif(10, min = -1, max = 1), b = runif(10, min = -1, max = 1))
my.plot <- xyplot(b ~ a, data = my.df)
update(my.plot, panel = function(...) {
            panel.abline(h = 0, v = 0, lty = "dotted", col = "light grey")
            panel.xyplot(...)
        })

在此处输入图像描述

If you're using package lattice (which is implied with xyplot), you can use panel.abline to draw lines over labeled ticks.

my.df <- data.frame(a = runif(10, min = -1, max = 1), b = runif(10, min = -1, max = 1))
my.plot <- xyplot(b ~ a, data = my.df)
update(my.plot, panel = function(...) {
            panel.abline(h = 0, v = 0, lty = "dotted", col = "light grey")
            panel.xyplot(...)
        })

enter image description here

睡美人的小仙女 2024-11-14 04:37:21

有一个lattice llines函数可以替代base中的lines()功能。还有一个 panel.lines 函数。

#---------- method --------------
 xyplot(-1:1 ~ -1:1, type="l")
trellis.focus("panel", 1, 1)
do.call("panel.abline", list(h=0,v=0, lty=3) )
trellis.unfocus()
# --- that method has the advantage of also demonstrating 
#        how to modify an existing plot

#---------- method 2--------------

 xp <-xyplot(-2:1 ~ -2:1, type="l", panel=function(...){
 panel.xyplot(...)
 panel.abline(h=0,v=0, lty=3)} )
xp

There is a lattice llines function that replaces the function of lines() functionality in base. There is also a panel.lines function.

#---------- method --------------
 xyplot(-1:1 ~ -1:1, type="l")
trellis.focus("panel", 1, 1)
do.call("panel.abline", list(h=0,v=0, lty=3) )
trellis.unfocus()
# --- that method has the advantage of also demonstrating 
#        how to modify an existing plot

#---------- method 2--------------

 xp <-xyplot(-2:1 ~ -2:1, type="l", panel=function(...){
 panel.xyplot(...)
 panel.abline(h=0,v=0, lty=3)} )
xp
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文