On Mar 31, 2011, at 8:41 AM, Peter Ehlers wrote:

On 2011-03-31 03:39, Rubén Roa wrote:

DeaR ComRades,

require(lattice)
data<- data.frame(SP=sort(rep(as.factor(c('A','B','C','D','E')),12)),
                   x=rpois(60,10),
                   y=rep(c(rep(0,4),rep(10,4),rep(20,4)),5),
                   z=rep(1:4,15))
xyplot(x~y| SP ,data =data,groups=z,layout=c(2,3),pch=1:4,lty=1:4,col='black',type='b')

How do I put a legend for the grouping variable in the empty upper- right panel?

See the help page for xyplot for an example using the iris data.
You just need to add something like

auto.key = list(x = .6, y = .7, corner = c(0, 0))

to your lattice call. See the 'key' entry on the ?xyplot page.

On my machine the default color scheme is TRUE, so the auto.key comes out with colored circles. This incantation gets the key to match the plotting symbols and lines:

xyplot(x~y|SP, data=data,groups=z, layout=c(2,3), par.settings=simpleTheme(pch=1:4,lty=1:4,col='black'), type="b",
auto.key = list(x = .6, y = .7, lines=TRUE, corner = c(0, 0)) )


Peter Ehlers


TIA

Rubén

____________________________________________________________________________________

Dr. Rubén Roa-Ureta
AZTI - Tecnalia / Marine Research Unit
Txatxarramendi Ugartea z/g
48395 Sukarrieta (Bizkaia)
SPAIN

______________________________________________
R-help@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.

______________________________________________
R-help@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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to