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. I've a feeling that the subscripts arguement is somehow involved, but I've not found any examples or references to this. Any suggestions? Which page of the various manuals did I skim too quickly? Thanks, Rob -- Robert Balshaw, Ph.D. -- Senior Biostatistician, Syreon Corp. -- Phone: 604.676.5900x220; Fax: 604.676.5911
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
> 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.I would do it with the groups parameter. xyplot (y ~ x | Visit, groups=Visit, panel=function(x,y,subscripts,groups,...) { panel.xyplot(x,y,...) g <- unique(groups[subscripts]) # g is the unique value of Visit occuring in this panel # so plot whatever lines you like, as a function of g } ) The groups argument to xyplot is an arbitrary vector of the same length as the data you are plotting. The function xyplot splits the data into panels. To each panel function it passes two arguments: group, which is just the same as the groups argument passed to xyplot; and subscripts, a vector of integers indexing the entries that will appear in this panel. Since in this case groups=Visit and the plot conditions on Visit, groups[subscripts] contains identical elements. If you had passed groups=SomethingElse to xyplot, groups[subscripts] would contain several values.> Any suggestions? Which page of the various manuals did I skim too quickly?The documentation I worked from is that for xyplot. And I looked at the definition of panel.superpose. Damon Wischik.