[R] conditioning variable in panel.xyplot?
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Mar 5 05:39:44 CET 2010
On Thu, Mar 4, 2010 at 4:42 PM, Seth W Bigelow <sbigelow at fs.fed.us> wrote:
> I wish to create a multipanel plot (map) from several datasets ("d" and
> "q" in the example below). I can condition the main xyplot statement on
> the "site" variable, but I don't know how to pass a conditioning variable
> to panel.xyplot plot so that the x-y coordinates from dataset q are only
> plotted at the appropriate site.
The keyword is 'subscripts'. Look at the entry for 'panel' in ?xyplot,
and let us know if you still have doubts.
-Deepayan
>
>
> library(lattice)
> d <- data.frame(site = c(rep("A",12), rep("B",12)),
> x=rnorm(24),y=rnorm(24)) # Create dataframe "d",
> with 12 x-y coordinates for each site
> q <- data.frame(site = c(rep("A",7), rep("B",7)),
> x=rnorm(14),y=rnorm(14)) # Create dataframe "q",
> with 7 pairs of x-y coordinates for each site.
>
> mypanel <- function(...){
> panel.xyplot(q$x, q$y, col="red") # Statement that
> needs a "Site" conditioning variable
> panel.xyplot(...)}
>
> xyplot(y~x|site, d, panel=mypanel) # Statement erroneously plots all
> 14 x-y points in "q" on panels for sites A & B
>
>
>
> Dr. Seth W. Bigelow
> Biologist, USDA-FS Pacific Southwest Research Station
> 1731 Research Park Drive, Davis California
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list