Hello, The latticeExtra::layer function uses non-standard evaluation. From its help page, Details section: " Note that the evaluation used in layer is non-standard, and can be confusing at first: you typically refer to variables as if inside the panel function (x,y, etc); you can usually refer to objects which exist in the global environment (workspace), but it is safer to pass them in by name in thedata argument to layer. (And this should not to be confused with thedata argument to the original xyplot.)"
Therefore, you will solve your problem with layer(panel.text(xi, yi, li), data=list(xi=xi, yi=yi, li=li)) On the other hand, you should have sent this message to the general R-Help mailing list instead to R-sig-Geo. Best, Oscar. El 26/01/2013 02:15, "Jooil Kim" <[email protected]> escribió: > > Hello list, > > I've created a function incorporating lattice, and I'm getting weird results that I can't explain > > Here's the results I would like to have, without encapsulating it into a function (this works without problems): > > A <- data.frame(x = rnorm(100), y = rnorm(100)) > xyplot(y ~ x, data = A) > trellis.focus("toplevel") ## has coordinate system [0,1] x [0,1] > panel.text(c(0.5, 0.6, 0.7), c(0.4, 0.2, 0.3), c("A", "B", "C"), cex = 1.2, font = 2) > trellis.unfocus() > > > I thought I could make up a function as such to do the same thing: > > test <- function(xi, yi, li){ > A <- data.frame(x = rnorm(100), y = rnorm(100)) > p <- xyplot(y ~ x, data = A) > trellis.focus("toplevel") ## has coordinate system [0,1] x [0,1] > p <- p + layer(panel.text(xi, yi, li, cex = 1.2, font = 2)) > trellis.unfocus() > > return(p) > } > > test(c(0.5, 0.6, 0.7), c(0.4, 0.2, 0.3), c("A", "B", "C")) > > > With my function, I get an error for the panel.text part, with the message "Error using packet 1 object 'xi' not found". > > Any help on this would be greatly appreciated! > > > Best regards, > > Jooil > > > ---------------------------------------------------- > Jooil Kim > Postdoc Fellow > Scripps Institution of Oceanography, UC San Diego > Mailing address: > 9500 Gilman Drive # 0244 > La Jolla, CA 92093-0244, USA > For FedEx/UPS: > 8675 Discovery Way, Vaughan Hall Rm. 447 > La Jolla, CA 92037, USA > > Tel. +1-858-534-2599 > Fax. +1-858-455-8306 > > _______________________________________________ > R-sig-Geo mailing list > [email protected] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
