Re: [R] Override col.lines and col.symbol in panel.xyplot with type='b'

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Tue, 12 Apr 2011 13:00:41 +0530

On Mon, Apr 11, 2011 at 9:27 PM, Szumiloski, John <john_szumiloski_at_merck.com> wrote:
> Dear useRs,
>
> I have a longitudinal experiment with several treatment groups, ~20 subjects per group, ~6 timepoints and a continuous dependent variable.  I have been successfully been using lattice::xyplot with this data.  However, I have been stumped with a particular application of it.
>
> I would like to use xyplot on my data, broken into treatment groups with the groups argument, using type='b' to show subjectwise longitudinal data.  So far so good, I have done this many times.  But now I wish to show the same data but having the color of the lines and symbols overridden in some arbitrary way, yet not without changing anything else about the plot, in particular the structure/topology of the plot from using the groups argument and type='b'.
>
> This requires using a panel function of some sort.

No, it does not. You are making things unnecessarily complicated.

When you use 'groups', colors are associated with levels of the grouping variable, not individual rows of your data. So:

set.seed(388659262)
dat <- data.frame(Panel=rep(c('A','B'), each=4),

                  ID=factor(rep(letters[1:4], each=2)),
                  X=rep(c(0,1), times=4),
                  Y=runif(8))

##### now for the arbitrary colors. Let's highlight one subject red, the rest black

myColor <- ifelse(levels(dat$ID) == "a", 2, 1)

xyplot(Y ~ X | Panel, data=dat, groups=ID,

       type='b', col = myColor,
       scales=list(x=list(at=c(0,1),labels=c(0,1))))

-Deepayan



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 Tue 12 Apr 2011 - 07:33:33 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 Tue 12 Apr 2011 - 07:50:28 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