[R-sig-Geo] Problems using lattice in a function?
Jooil Kim
kji2080 at gmail.com
Sat Jan 26 02:14:16 CET 2013
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
More information about the R-sig-Geo
mailing list