[R] Lattice xyplot(): adding a legend

Duncan Mackay dulcalma at bigpond.com
Thu Oct 20 07:10:32 CEST 2016


Hi Rich

Without an example to check I think you need to fill in the arguments for
par.settings eg 

par.settings = list(plot.symbol = list(c("black","red","dark green","dark
blue","dark goldenrod","purple"),
                                                                        pch
= 20,
                                                                       cex =
1),
if you have groups 

par.settings = list(superpose.symbol = list(c("black","red","dark
green","dark blue","dark goldenrod","purple"),
 
pch = 20,
 
cex = 1)),

For other types such as barchart  type 
barchart  and at the top there is

plot.symbol <- trellis.par.get("plot.symbol")
    plot.line <- trellis.par.get("plot.line")
    superpose.symbol <- trellis.par.get("superpose.symbol")
    superpose.line <- trellis.par.get("superpose.line")

Similar occurs for panel.xyplot

I find that ? xyplot  and ?panel. ... give the most uptodate methods things
change overtime.
There are some words on how information is passed to the key in ?xyplot
You either have to set trellis.par.set() or use the par.settings arguments

For older versions things may be slightly different.

If in a hurry I try the easiest but if that fails on the first go I just use
key = list(text = ... etc
 
Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au


-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Rich Shepard
Sent: Thursday, 20 October 2016 10:05
To: r-help at r-project.org
Subject: Re: [R] Lattice xyplot(): adding a legend

On Wed, 19 Oct 2016, Rich Shepard wrote:

>  I did read that but mis-applied what I read. Tried auto.key but that did
> not work as desired. Now I know to learn how to apply 'key'.

   Almost there after another careful reading Section 9.2.3 ff in the book.
Here's the command to produce the plot:

rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area
Precipitation",
     ylab = "Daily Total Amount (in)", xlab = "Date",
     scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
     y = list(at=c(min(rain$amount), max(rain$amount)))),
     pch = 20,
     col = c("black","red","dark green","dark blue","dark
goldenrod","purple"),
     key = simpleKey(text = levels(rain$station)[1:6],
       x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))

   My question is how to pass pch = 20 to the key. simpleKey accepts only
the
logical TRUE as an argument and this produces a plot with filled circles for
the data but unfilled circles for the key. I find no example of specifying
pch for points in the key in either the book or ?xyplot, and I'm sure there
is a way of having the key symbols match both pch and color as the data
symbols.

   Is use of Rows() the solution?

Rich

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.



More information about the R-help mailing list