[R] Constructing an additional key inside of a lattice panel
Felix Andrews
felix at nfrac.org
Thu Aug 18 14:21:46 CEST 2011
'corner' is not a valid name for a component of 'legend'. See ?xyplot
Try
xyplot(1 ~ 1,
legend = list(inside =
list(fun="draw.key",
args = list(
key = list(
text = list(month.name[1:2]),
lines = list(lty = 1:2)
),
draw = TRUE
),
corner = c(0, .98)
)
)
)
On 18 August 2011 21:05, Fredrik Karlsson <dargosch at gmail.com> wrote:
> Dear Deepayan,
>
> Thank you for your quick and enlightening reply. I'll try making a modifies
> version of the two functions and see what I end up with..
>
> However, out of pure curiosity, what is wrong with the "legend" I
> constructed below:
>
> legend=list(corner=list(
> fun=draw.key,
> args=list(
> key=list(text=
> list(myFactorLevels),
> lines=list(
> lty=1:length(myFactorLevels))
> ),
> draw=TRUE
> )
> ),x=0,y=1
>
> It gives me nothing (not even an error message :-)), so I have no idea about
> what I did wrong here.
>
> I would very much appreciate any insight on this.
>
> /Fredrik
>
>
> On Wed, Aug 17, 2011 at 2:57 PM, Deepayan Sarkar
> <deepayan.sarkar at gmail.com>wrote:
>
>> 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
>>
>
>
>
> --
> "Life is like a trumpet - if you don't put anything into it, you don't get
> anything out of it."
>
> [[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.
>
--
Felix Andrews / 安福立
http://www.neurofractal.org/felix/
More information about the R-help
mailing list