[R] Adding reference lines to xyplot
Deepayan Sarkar
deepayan at stat.wisc.edu
Mon Jan 20 22:33:02 CET 2003
On Monday 20 January 2003 02:37 pm, Rob Balshaw wrote:
> I'm trying to add a set of reference lines to a multipanel xyplot
>
> xyplot(y ~ x | Visit,
> panel = function(x, y, ...){
> panel.xyplot(x, y, ...)
> abline(v = c(0.5, 1))
> })
>
> However, the reference lines are different for different visits. For
> example, for the first 2 visits, I'd like vertical lines at x = 0.5 and 1.
> For visits 3 and four, I'd like vertical lines at x = 1 and 1.5. I can use
> abline within the panel function, but I haven't found a way to say I want
> my reference lines to change for different visits.
panel functions are not given any info regarding which panel is being drawn,
so there is no direct way to do this. One way that works in most cases is
something like:
panel.index <- 1
xyplot(y ~ x | Visit,
panel = function(x, y, ...){
panel.xyplot(x, y, ...)
panel.abline(v = if (index %in% 1:2) c(0.5, 1) else c(1, 1.5))
panel.index <<- panel.index + 1
})
Deepayan
More information about the R-help
mailing list