【发布时间】:2011-05-15 14:04:30
【问题描述】:
我有一个xyplot,我想在 0 值上绘制网格线。
如何做到这一点?
【问题讨论】:
我有一个xyplot,我想在 0 值上绘制网格线。
如何做到这一点?
【问题讨论】:
格子 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))
如果你想要panel.grid 喜欢的线条样式,那么不错的技巧:
xyplot(yy~xx, X, abline=c(list(h=0),trellis.par.get("reference.line")))
【讨论】:
如果您使用包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(...)
})
【讨论】:
有一个 lattice llines 函数替换了 base.line() 函数中的函数。还有一个 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
【讨论】: