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

Marius Hofert m_hofert at web.de
Tue Feb 8 16:55:28 CET 2011


Dear Peter,

thanks for your response. Since in my original problem, the "abline" depends on i [but neither on x nor y], I tried something like this:

library(lattice)
plot.list <- vector("list", 4)
for(i in 1:4){
   plot.list[[i]] <- xyplot(1~1, type="p", xlim=c(0,11),
   panel=function(x, y, i, ...){
	panel.xyplot(x, y, ...)
	panel.abline(v = sqrt(i))
   })
}
plot.list[[2]]

How can I pass through the "i"? It should be possible to draw a line with a parameter depending on "i". 

Cheers,

Marius


On 2011-02-08, at 16:22 , Peter Ehlers wrote:

> On 2011-02-08 06:28, Marius Hofert wrote:
>> Dear Karl,
>> 
>> thanks for your answer.
>> 
>> I am still wondering why the point "i~i" is plotted at "i" but not the vertical line? And how I can plot the vertical line at "i". Do you know a solution?
> 
> Marius, try this:
> 
> plot.list <- vector("list", 3)
> for(i in 1:3){
>    plot.list[[i]] <- xyplot(i~i, type="p", xlim=c(0,11),
>    panel=function(x, y,...){
> 	panel.xyplot(x, y,...)
> 	panel.abline(v = x)
>    })
> }
> plot.list[[1]]
> 
> Peter Ehlers
> 
>> 
>> Cheers,
>> 
>> Marius
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 



More information about the R-help mailing list