[R] Lattice: choice of symbol and symbol position in legend
Peter Ehlers
ehlers at ucalgary.ca
Tue Jul 26 20:07:18 CEST 2011
On 2011-07-26 08:47, marcel wrote:
> I am making final adjustments to a multi-plot figure using basic and lattice.
> In the lattice plot, I would like to include a legend that matches the
> format of the legends in the other plots, which consist of appropriately
> colored squares (pch 22) followed by text. In lattice, I was able to get a
> legend using
>
> auto.key = list(x = .6, y = .6, corner = c(0, 0), pch=22)
>
> but my request for pch=22 was ignored, the colors did not seem to match the
> bars exactly, and the positioning was 'text' followed by 'symbol' instead of
> the other way around. I looked through the help sections but did not find
> any detailed documentation on this. Can these be adjusted? Many thanks.
For final plots I usually prefer the more flexible key().
Here's an example using the iris data; presumably you want
pch=22 for the plotting character as well. Otherwise, you
can replace the par.settings list with simply col=c(2,3,4).
xyplot(Sepal.Length ~ Petal.Length, groups = Species,
data = iris,
par.settings = list(superpose.symbol = list(
col = c(2,4,3),
pch = 22,
fill = "transparent")),
key = list(x = .1, y = .8, corner = c(0, 0),
points = list(pch=22, col=c(2,4,3), cex=1.5),
text = list(levels(iris$Species))))
?xyplot gives a number of other key() parameters that can be
adjusted.
Peter Ehlers
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Lattice-choice-of-symbol-and-symbol-position-in-legend-tp3696182p3696182.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list