Hi Jooil, Some weeks ago I got a similar problem on building a function using Lattice, and the Oscar's instructions helped me. It seem like a recurrent problem, may be if you write to R-Help as Oscar says, you can suggest to the Lattice Developers to change that behaviour.
Best regards. > Message: 4 > Date: Sat, 26 Jan 2013 08:57:52 +0100 > From: Oscar Perpi?an <[email protected]> > To: Jooil Kim <[email protected]> > Cc: [email protected] > Subject: Re: [R-sig-Geo] Problems using lattice in a function? > Message-ID: > <CAMLL7bnNPxK=UUWfdKcUnyDBA8oRoQowJ= > [email protected]> > Content-Type: text/plain > > 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]] -- ************************************************************ Federico *Vladimir* Gutierrez Corea www.vlado.es PhD Candidate at Technical University of Madrid (UPM) MERCATOR Research Group Campus SUR , Paseo de la Arboleda s/n. E-28031 Madrid (Spain) E-Mail: [email protected] Ph.: +34 91 331 1968 (University) Fax.: +34 91 331 1968 (University) ************************************************************ See *Vladimir* on Linked-In <http://es.linkedin.com/in/fvgutierrez> See *Vladimir* on GeoI+D Research Center at UPM<http://www.upm.es/observatorio/vi/index.jsp?pageac=investigador.jsp&idInvestigador=11805> See *Vladimir* on Google-Scientific Publications<http://scholar.google.es/scholar?start=0&q=F.+Vladimir+Gutierrez-Corea&hl=en&as_sdt=1> ************************************************************ [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
