Fredrik Karlsson
2011-Aug-16 11:05 UTC
[R] Constructing an additional key inside of a lattice panel
An embedded and charset-unspecified text was scrubbed... Name: inte tillg?nglig URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110816/b1fd368c/attachment.pl>
Fredrik Karlsson
2011-Aug-17 08:25 UTC
[R] Constructing an additional key inside of a lattice panel
An embedded and charset-unspecified text was scrubbed... Name: inte tillg?nglig URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110817/47f17b23/attachment.pl>
Deepayan Sarkar
2011-Aug-17 12:57 UTC
[R] Constructing an additional key inside of a lattice panel
On Tue, Aug 16, 2011 at 4:35 PM, Fredrik Karlsson <dargosch at gmail.com> wrote:> Hi, > > I would like to add an additional key inside of a panel based on a factor > that is not the "groups" argument. > I've tried using the panel.key function in latticeExtras, but I cannot get > the line types the way I want it. > > Using my factor myGroups, I've tried this: > > panel.key(text=levels(myGroups),lines=TRUE,points=FALSE,corner > c(0,.98),key=list(lines=list(lty=1:length(levels(myGroups))))) > > I then get the key where I want it, the text is right, but line types are > not correct (always lty=1, I think). > > Any ideas on how I could solve this?Well, trying to add undocumented arguments and hoping they will magically work usually doesn't help. panel.key() works using simpleKey(), which by design is simple but not flexible. In particular, it will not allow you to set 'lty' directly, and instead use the values from the theme currently in use. You _can_ change the theme also, using a different argument; e.g., library(lattice) library(latticeExtra) xyplot(1 ~ 1, panel = function(...) { panel.xyplot(...) panel.key(text = month.name[1:2],lines=TRUE,points=FALSE, corner = c(0,.98)) }, par.settings = simpleTheme(lty = 1:2)) But I don't know if that interferes with the rest of your call. If all else fails, panel.key() is not a very complicated function, so you can take inspiration from it and write your own version that replaces the line key <- simpleKey(text, ...) with key <- <something else> where <something else> describes the legend that you want. -Deepayan