In xyplot, I would like to get the "data into the panel function" in the following sense: Consider xyplot(scc~time|cowidp, data=cow.s,type=c("l"), panel=function(x,y,subscripts,...){ panel.xyplot(x,y,...) vvv<-cow.s[which(!is.na(cow.s[subscripts,"mastreat"])),"time"] panel.abline(v=vvv,col="red",lwd=2) } ) If I want to use a different dataset, say cow.2, I would have to modify the code twice in the panel function. Is there a way of avoiding this? Best regards Søren [[alternative HTML version deleted]]
S?ren H?jsgaard wrote:> In xyplot, I would like to get the "data into the panel function" in the following sense: Consider > > xyplot(scc~time|cowidp, data=cow.s,type=c("l"), > panel=function(x,y,subscripts,...){ > panel.xyplot(x,y,...) > vvv<-cow.s[which(!is.na(cow.s[subscripts,"mastreat"])),"time"] > panel.abline(v=vvv,col="red",lwd=2) > } > ) > > If I want to use a different dataset, say cow.2, I would have to modify the code twice in the panel function. Is there a way of avoiding this? > > Best regards > S?ren > > [[alternative HTML version deleted]] > >Hi, S?ren, I usually do this by creating a wrapper function: plot.cow <- function(formula = ssc ~ time | cowidp, data, ...) { xyplot(formula, data = data, type = "l", panel = function(x, y, subscripts, time, mastreat, ...) { panel.xyplot(x, y, ...) vvv <- time[which(!is.na(mastreat[subscripts])] panel.abline(v = vvv, col = "red", lwd = 2) }, time = data$time, mastreat = data$mastreat) } plot.cow(cow.s) plot.cow(cow.2) HTH, --sundar
On 4/4/06, S?ren H?jsgaard <Soren.Hojsgaard at agrsci.dk> wrote:> In xyplot, I would like to get the "data into the panel function" in the > following sense: Consider > > xyplot(scc~time|cowidp, data=cow.s,type=c("l"), > panel=function(x,y,subscripts,...){ > panel.xyplot(x,y,...) > vvv<-cow.s[which(!is.na(cow.s[subscripts,"mastreat"])),"time"] > panel.abline(v=vvv,col="red",lwd=2) > } > )It's hard to be sure without an example, but how is this any different from xyplot(scc~time|cowidp, data=cow.s, type=c("l"), panel=function(x, y, ...) { panel.xyplot(x,y,...) panel.abline(v = x, col="red",lwd=2) }) ? -Deepayan
Maybe Matching Threads
- sqlQuery of variable of type varchar - confusion with "."
- xyplot: Plotting two variables, one as points - the other as line. Can that be done without explicitly using panel functions
- lattice/xyplot: plotting 4 variables in two panels - can this be done?
- Calling substitute(expr, list(a=1)) when expr <- expression(a+b+c)
- Evaluating f(x(2,3)) on a function f<- function(a,b){a+b}