Re: [R] auto.key in xyplot in conjunction with panel.text

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Wed, 02 Jul 2008 15:45:51 -0700

On 7/2/08, David Afshartous <dafshartous_at_med.miami.edu> wrote:
>
>
> 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.

You can't really expect it to work unless you go through panel.superpose. Try this:

xyplot(Y ~ X, data = dat, lab = dat$ID,

       groups = Drug,
       auto.key = list(space = "top", text = c("Placebo", "Drug"),
                       points = FALSE, lines = TRUE),
       par.settings = list(superpose.line = list(col = c("red","black"))),
       panel = panel.superpose,
       panel.groups = function(x, y, lab, subscripts, col.line, ...){
           panel.text(x, y, labels = lab[subscripts], col = col.line)
       })

-Deepayan

> 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_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.
>



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. Received on Wed 02 Jul 2008 - 22:48:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jul 2008 - 14:31:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive