[R] "strange" behavior of panel.abline inside a for-loop

Karl Ove Hufthammer karl at huftis.org
Tue Feb 8 13:39:19 CET 2011


Marius Hofert wrote:

> library(lattice)
> plot.list <- vector("list", 10)
> for(i in 1:10){
> plot.list[[i]] <- xyplot(i~i, type="p", xlim=c(0,11), panel=function(...){
> panel.xyplot(...)
> panel.abline(v=i)
> })
> }
> plot.list[[3]]
> 
> As  you can see, the vertical line is always printed at x=10 [and not at
> x=i]. Why?

No, it’s printed at x=i, which is 10 at the end of the loop. You can see 
this by changing i to for example 5 and rerunning ‘plot.list[[3]]’.

-- 
Karl Ove Hufthammer



More information about the R-help mailing list