[R] multiple "keys" in Trellis plots?
Deepayan Sarkar
deepayansarkar at yahoo.com
Thu Sep 12 05:52:00 CEST 2002
Hi,
If you need to do something on a per panel basis, you have to include that in
the panel function. keys can be drawn (in any grid viewport) with the draw.key
function. For example (with your data),
key <- list(key1 = list(text = list(paste("myFrame1", 1:3))),
key2 = list(text = list(paste("myFrame2", 4:6))))
i <- 1
print(xyplot(a ~ b | which, myFrame, groups=c,
panel = function(...) {
panel.superpose(...)
draw.key(key[[i]], draw = TRUE, vp = viewport(.6, .9))
i <<- i + 1
},
t="l"))
(I'm using an indexing variable i because the panel function isn't passed
information on which panel is being drawn. It wouldn't be necessary If your key
can be defined just in terms of the data passed to the panel function)
Hope that helps.
Deepayan
--- "Bartz, Kevin" <Kevin.Bartz at FMR.COM> wrote:
> My xyplot has a number of panels, and I'd like a separate key for each
> rather than a single key for the entire set. However, I cannot find a way to
> pass multiple key definitions to xyplot's "key" argument.
>
> Allow me to throw out a simple example:
>
> require(methods)
> require(lattice)
>
> ## define sample data
> myFrame1 <- data.frame(a=1:100, b=rep(1:10,10), c=unlist(lapply(1:10, rep,
> 10)))
> myFrame2 <- data.frame(a=50:1, b=rep(1:10,5), c=unlist(lapply(1:5, rep,
> 10)))
> myFrame <- cbind(rbind(myFrame1, myFrame2),
> which=c(rep("Display for myFrame1", 100),
> rep("Display for myFrame2", 50)))
>
> ## now send the data to a Trellis device
> trellis.device()
> print(xyplot(a ~ b | which, myFrame, groups=c,
> key=list(text=list(lab=paste("myFrame1 Line", 1:10))),
> panel="panel.superpose", t="l"))
>
> What I really want here is two separate keys, one for the plot on the first
> panel, representing the lines in myFrame1, and one for the plot on the
> second, representing the lines in myFrame2.
>
> Can anyone suggest a solution?
>
> Thanks,
>
> Kevin
>
> > R.version
> _
> platform sparc-sun-solaris2.6
> arch sparc
> os solaris2.6
> system sparc, solaris2.6
> status
> major 1
> minor 5.1
> year 2002
> month 06
> day 17
> language R
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
__________________________________________________
Yahoo! News - Today's headlines
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list