All,

I can't seem to get auto.key to work properly in an xyplot that is employing
panel.text.  Specifically, I often change the default grouping colors then
use auto.key accordingly, but for some reason the same functionality isn't
working for this different type of plot.  Any help much appreciated.

Cheers, 
David




library("lattice")
dat = data.frame( Y = c(rnorm(18,1), rnorm(18,3)), X = rep(c(1:18), 2),
ID = rep(c(1:18), 2), Drug = factor(rep(c("P", "D"), each = 18)) )
## this plot correctly provides the key for the grouping color
xyplot(Y ~ X, data=dat, type="p",
       panel=panel.superpose, groups=Drug,
       col = rep(c("red", "black"), 18),
       auto.key = list(space = "top",  text = c( "Placebo", "Drug"),
       points = FALSE, lines = TRUE),
par.settings = list(superpose.line = list(col = c("red","black") ) ) )



## this plot correctly uses ID's and colors instead of plotting symbols
xyplot(Y ~ X, data=dat, type="n", lab = dat$ID,
       groups=Drug, col = rep(c("red", "black"), 18),
       panel= function(x,y, lab, type, auto.key, ...){
            panel.xyplot(x,y, type = type, ...)
            panel.text(x,y, lab=lab,  ...)
   }
)

## when trying to get the correct key as in the first plot
## for the second plot things don't work.
## I've tried several alterations to the syntax but no luck so far
xyplot(Y ~ X, data=dat, type="n", lab = dat$ID,
       groups=Drug, col = rep(c("red", "black"), 18),
       auto.key = list(space = "top",  text = c( "Placebo", "Drug"),
       points = FALSE, lines = TRUE), par.settings = list(superpose.line =
       list(col = c("red","black") ) )
       panel= function(x,y, lab, type, ...){
            panel.xyplot(x,y, type = type, ...)
            panel.text(x,y, lab=lab,  ...)
   }
)

## another unsuccessful attempt:
xyplot(Y ~ X, data=dat, type="n", lab = dat$ID,
       groups=Drug, col = rep(c("red", "black"), 18),
       auto.key = list(space = "top",  text = c( "Placebo", "Drug"),
       points = FALSE, lines = TRUE), par.settings = list(superpose.line =
       list(col = c("red","black") ) )
       panel= function(x,y, lab, type, auto.key ...){
            panel.xyplot(x,y, type = type, auto.key = auto.key ...)
            panel.text(x,y, lab=lab,  ...)
   }
)

______________________________________________
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