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
Problems using lattice in a function?
3 messages · Jooil Kim, Oscar Perpiñan
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130126/90fe5a6f/attachment.pl>
Hello Oscar, Thank you very much for the prompt reply, problem certainly solved, and I can sleep in peace! : ) And I apologize for posting to the wrong forum (I also realized I forgot to post the details of my R setup!). The graphs I will eventually create are based on spatial data, and I had blindly thought I should ask here. Thanks again! Cheers, 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
On Jan 25, 2013, at 11:57 PM, Oscar Perpi?an <oscar.perpinan at gmail.com> wrote:
layer(panel.text(xi, yi, li), data=list(xi=xi, yi=yi, li=li))