[R] lattice legen and auto.key conflict
deepayan.sarkar at gmail.com
Tue Jul 31 08:55:38 CEST 2012
On Mon, Jul 30, 2012 at 10:16 PM, Bert Gunter <gunter.berton at gene.com> wrote:
> I think one needs to carefully parse the xyplot help, where it says:
> "To use more than one legend, or to have arbitrary legends not
> constrained by the structure imposed by key, use the legend argument.
> So I presume that this is to be interpreted as: "ONLY the legend
> argument will be used when both key(including auto.key) and legend
> arguments are given." However, this is not clear to me either. The
> Help appears to leave the behavior when one tries to use both
The help could indeed use some love.
Note however, that the entry for 'auto.key' (surely relevant here) says that:
More precisely, if 'auto.key' is not 'FALSE', 'groups' is
non-null, and there is no 'key' or 'legend' argument
specified in the call, a key is created with 'simpleKey' with
'levels(groups)' as the first ('text') argument.
And that condition is not satisfied here.
So that leaves the following two options (use key=, or update). The
documentation is silent about whether or not these should be
successful, but fortunately both seem to work.
groups = Species,
key = simpleKey(text = levels(iris$Species), space="right"),
p <- xyplot(Sepal.Length+Sepal.Width~Petal.Length+Petal.Width,
data=iris, groups=Species, auto.key=list(space="right"))
update(p, legend=list(bottom=list(fun=grid.text,args=list(label="youpi !"))))
(I wish that reading lattice help would be less like trying to follow
an Asimov robot story, but there are too many possible interactions to
document both comprehensively and accurately.)
More information about the R-help