[R] Odp: adding a reference line to an xyplot

Petr PIKAL petr.pikal at precheza.cz
Fri Feb 20 14:36:12 CET 2009


Hi

r-help-bounces at r-project.org napsal dne 20.02.2009 10:34:02:

> 
> 
> Hi,
> 
> I want to add a dashed vertical line to a number of xyplots.
> 
> Here is a simple script of the type of plot I have but then I want to 
add a
> reference line to 1995 on each of the panels.  I have tried panel.abline 
and
> other suggestions on the forum but can't get it to work.
> 
> plot<-rep(letters[1:3],each=10)
> year<-rep(1991:2000,times=3)
> matter<-rep(seq(2,6.5,0.5),times=3)
> xyplot(matter~year|plot,type="l")

Here is a function which I adapted from Gabor Grothendieck's suggestion

addLine<- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) { 
tcL <- trellis.currentLayout()
k<-0
for(i in 1:nrow(tcL))
  for(j in 1:ncol(tcL))
    if (tcL[i,j] > 0) {
k<-k+1
        trellis.focus("panel", j, i, highlight = FALSE)
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else 
panel.abline(a=a, b=b, v=v, h=h, ...)
        trellis.unfocus()
        }
}

It works on plotted xyplot, accepts single value or vector of values which 
can be different for each panel.

Regards
Petr

> 
> Cheers,
> Chris 
> -- 
> View this message in context: 
http://www.nabble.com/adding-a-reference-line-
> to-an-xyplot-tp22117545p22117545.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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