[R] Lattice xyplot(): adding a legend

Rich Shepard rshepard at appl-ecosys.com
Thu Oct 20 01:04:59 CEST 2016


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



More information about the R-help mailing list