Re: [R] Superimposing y-variables in Lattice formulas

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri, 14 Nov 2008 15:55:42 -0800

On Fri, Nov 14, 2008 at 1:23 PM, Stavros Macrakis <macrakis_at_alum.mit.edu> wrote:
> Given a data frame of a categorical variable and two continuous
> variables, I would like to display one continuous variable against the
> other for each value of the categorical variable, all superimposed on
> the same plot. For example:
>
> data(Indometh); str(Indometh)
> Classes 'nfnGroupedData', 'nfGroupedData', 'groupedData' and
> 'data.frame': 66 obs. of 3 variables:
> $ Subject: Ord.factor w/ 6 levels "1"<"4"<"2"<"5"<..: 1 1 1 1 1 1 1 1 1 1 ...
> $ time : num 0.25 0.5 0.75 1 1.25 2 3 4 5 6 ...
> $ conc : num 1.5 0.94 0.78 0.48 0.37 0.19 0.12 0.11 0.08 0.07 ...
> ...
>
> I can easily display conc as a function of time with one panel per
> value of the categorical variable:
>
> xyplot ( conc ~ time | Subject , Indometh )
>
> But how do I specify that I want to display all the Subjects on a
> single graph, superimposing them all?

Have you tried

xyplot ( conc ~ time , Indometh, groups = Subject )

?

-Deepayan

> I have played with various
> combinations of the formula operators ~, *, +, :, and |, but not
> gotten anywhere, and I haven't been able to find a clear description
> of the semantics of these operators either in the xyplot man page or
> in Murrell's R Graphics
>
> What I'm looking for is something like the output of:
>
> I <- Indometh;
> for (i in I$Subject)
> { (if (i==1) plot else points)(
> I[ I$Subject==i, c("time","conc")],
> col=i, type="l");
> par(new=TRUE); }
> par(new=FALSE);
>
> I recognize this is atrocious programming style, but I'm afraid I
> don't know any better; I would appreciate guidance on how to do this
> right in traditional graphics, too....
>
> -s
>
> ______________________________________________
> 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 Fri 14 Nov 2008 - 23:57:35 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 Sat 15 Nov 2008 - 18:30:26 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