I have stumbled across something in the Lattice package that is vexing me. Consider the code below: __________________________________________________________
library(lattice) myData <- expand.grid(sub = factor(1:16), time = 1:10) myData$observed <- rnorm(nrow(myData)) myData$fitted <- with(myData, ave(observed, sub, FUN = mean)) myData$event.time <- with(myData, ave(observed, sub, FUN = function(.x) 10 * runif(1))) myData <- myData[order(myData$sub, myData$time),] # This version works... xyplot( fitted + observed ~ time | sub, data = myData, subscripts = TRUE, panel = function(..., groups = groups, subscripts = subscripts) { panel.xyplot(..., groups = groups, subscripts = subscripts) event.time <- unique(myData$event.time[subscripts]) panel.abline(v = event.time, lty = 2, col = 'green') }, type = c('l','p'), distribute.type = TRUE, as.table = TRUE ) # ...but when you add the subset parameter it produces multiple index lines per subject xyplot( fitted + observed ~ time | sub, data = myData, subset = sub %in% sample(unique(sub), 9), subscripts = TRUE, panel = function(..., groups = groups, subscripts = subscripts) { panel.xyplot(..., groups = groups, subscripts = subscripts) event.time <- unique(myData$event.time[subscripts]) # print(event.time) panel.abline(v = event.time, lty = 2, col = 'green') }, type = c('l','p'), distribute.type = TRUE, as.table = TRUE ) ___________________________________________________________________ The (commented out) print statement I think indicates that there is a data reordering going on for the second example, that is causing the multiple index lines issue. Is there a neat solution to get the correct index lines per subject, or do I need a workaround? Or am I missing something fundamental in the code above that is causing issues? > sessionInfo() R version 2.7.0 (2008-04-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.17-6 loaded via a namespace (and not attached): [1] grid_2.7.0 Thanks, Jim Price Cardiome Pharmaceutical Corporation. -- View this message in context: http://www.nabble.com/xyplot%3A-subscripts%2C-groups-and-subset-tp17282996p17282996.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.