|
Hello R-helpers,
I'm trying to customize a graphic in lattice using the 'legend' argument to add labels on my plot but in the process I'm losing the legend drawn by 'auto.key', despite the fact that I'm actually not sticking these on the same sides of the graphic. I worked up a quick and simple example with the iris data : ### here's the basic graph xyplot(Sepal.Length+Sepal.Width~Petal.Length+Petal.Width,data=iris,groups=Species,auto.key=list(space="right")) ### now I try to add a 'legend' argument : xyplot(Sepal.Length+Sepal.Width~Petal.Length+Petal.Width,data=iris,groups=Species,auto.key=list(space="right"),legend=list(bottom=list(fun=grid.text,args=list(label="youpi !")))) ### and sadly the my initial legend has disappeared... Any pointers ? Many thanks in advance for your help David Gouache ARVALIS - Institut du Végétal Service Génétique Physiologie et Protection des Plantes IBP - Université Paris Sud Rue de Noetzlin - Bât. 630 91405 - ORSAY CEDEX (Adresse Postale) 91190 - GIF SUR YVETTE (Adresse GPS, livraison) Tél : +33.(0)1.69.93.85.60 Port : +33.(0)6.86.08.94.32 Fax : +33.(0)1.69.93.85.69 [[alternative HTML version deleted]] ______________________________________________ [hidden email] 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. |
|
David:
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 unspecified. -- Bert On Mon, Jul 30, 2012 at 9:10 AM, GOUACHE David <[hidden email]> wrote: > Hello R-helpers, > > I'm trying to customize a graphic in lattice using the 'legend' argument to add labels on my plot but in the process I'm losing the legend drawn by 'auto.key', despite the fact that I'm actually not sticking these on the same sides of the graphic. I worked up a quick and simple example with the iris data : > > ### here's the basic graph > xyplot(Sepal.Length+Sepal.Width~Petal.Length+Petal.Width,data=iris,groups=Species,auto.key=list(space="right")) > > ### now I try to add a 'legend' argument : > xyplot(Sepal.Length+Sepal.Width~Petal.Length+Petal.Width,data=iris,groups=Species,auto.key=list(space="right"),legend=list(bottom=list(fun=grid.text,args=list(label="youpi !")))) > > ### and sadly the my initial legend has disappeared... > > > Any pointers ? > Many thanks in advance for your help > > David Gouache > ARVALIS - Institut du Végétal > Service Génétique Physiologie et Protection des Plantes > IBP - Université Paris Sud > Rue de Noetzlin - Bât. 630 > 91405 - ORSAY CEDEX (Adresse Postale) > 91190 - GIF SUR YVETTE (Adresse GPS, livraison) > Tél : +33.(0)1.69.93.85.60 > Port : +33.(0)6.86.08.94.32 > Fax : +33.(0)1.69.93.85.69 > > > [[alternative HTML version deleted]] > > > ______________________________________________ > [hidden email] 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. > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ [hidden email] 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. |
|
On Mon, Jul 30, 2012 at 10:16 PM, Bert Gunter <[hidden email]> wrote:
> David: > > 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 > unspecified. 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. xyplot(Sepal.Length+Sepal.Width~Petal.Length+Petal.Width, data=iris, groups = Species, key = simpleKey(text = levels(iris$Species), space="right"), legend=list(bottom=list(fun=grid.text,args=list(label="youpi !")))) ## or 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.) -Deepayan ______________________________________________ [hidden email] 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. |
|
On 2012-07-30 23:55, Deepayan Sarkar wrote:
> > (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.) I, Robot, having assessed said lattice help, determine it to be admirable in execution. My master agrees. Peter Ehlers ______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
