2011-05-15 65 views

回答

5

如果你使用包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(...) 
     }) 

enter image description here

+0

感謝您的幫助,這就是我需要的 – weblover 2011-05-16 10:02:41

1

有一個lattice llines函數可以替換基線中的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 
+1

能夠 你給我一個例子請 – weblover 2011-05-15 14:25:43

9

根據lattice changelog

變化格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"))) 

Lattice graph with added nice style line