Re: [R] Types in grouped multi-panel (lattice) xyplot

From: Aaron Arvey <aarvey_at_cs.ucsd.edu>
Date: Thu, 10 Apr 2008 14:20:40 -0700 (PDT)

On Thu, 10 Apr 2008, Deepayan Sarkar wrote:

> On 4/10/08, Deepayan Sarkar <deepayan.sarkar_at_gmail.com> wrote:

>> On 4/10/08, Aaron Arvey <aarvey_at_cs.ucsd.edu> wrote:
>> > Apologetic prologue: I've looked through the mailing list for an answer to
>> > this (since I'm sure it's trivial) but I have not been able to find a fix.
>> >
>> > So the problem is that I want each group to have a different type of plot.
>> > "Probes" should be points and "Segments" should be lines (preferably using
>> > the segment plot command, but I've just been trying -- unsuccessfully --
>> > to get lines to work).
>> >
>> > To be exact, the data looks like:
>> >
>> > loc val valtype mouse
>> > 1428 0.1812367 Probes 2
>> > 1439 -0.4534155 Probes 2
>> > 1499 -0.4957303 Probes 2
>> > 1559 0.2448838 Probes 2
>> > 1611 -0.2030937 Probes 2
>> > 1788 -0.2235331 Probes 2
>> > 1428 0.5 Segment 2
>> > 1439 0.5 Segment 2
>> > 1499 0.5 Segment 2
>> > 1559 0.5 Segment 2
>> > 1611 0.5 Segment 2
>> > 1788 0.5 Segment 2
>> > 1428 0.1812367 Probes 1
>> > 1439 -0.4534155 Probes 1
>> > 1499 -0.4957303 Probes 1
>> > 1559 0.2448838 Probes 1
>> > 1611 -0.2030937 Probes 1
>> > 1788 -0.2235331 Probes 1
>> > 1428 0.5 Segment 1
>> > 1439 0.5 Segment 1
>> > 1499 0.5 Segment 1
>> > 1559 0.1 Segment 1
>> > 1611 0.1 Segment 1
>> > 1788 0.1 Segment 1
>> >
>> >
>> > * loc is the x-axis location
>> > * val is the y-axis value
>> > * valtype is equal to "which" had I been smart and used make.groups
>> > * mouse is the 'cond' variable
>> >
>> >
>> > The plot command I'm currently using is,
>> >
>> > xyplot(val ~ loc | mouse, data = df,
>> > groups=valtype
>> > aspect=0.5, layout=c(3,3),
>> > lty=0, lwd=3, type="p",
>> > col=c("black", "blue"),
>> > as.table = TRUE)
>> >
>> > which gives me black and blue points for the probes/segments (I've infered
>> > alphabetical order for the groups colors). When I change the type to
>> > c("p", "l"), I get
>> >
>> > xyplot(val ~ loc | mouse, data = df,
>> > groups=valtype
>> > aspect=0.5, layout=c(3,3),
>> > lty=0, lwd=3, type=c("p","l"),
>> > col=c("black", "blue"),
>> > as.table = TRUE)
>>
>>

>> Try
>>
>>

>> xyplot(val ~ loc | mouse, data = df,
>>

>> groups=valtype,
>> type=c("p","l"),
>> ## distribute.type = TRUE,
> > Sorry, that should be > > distribute.type = TRUE, >
>> col=c("black", "blue"))
That did exactly what I was looking for! I now have a very nice lattice plot with points and lines!
>> > I get the exact same plot. I've tried using a few of the panel functions
>> > I found on the list (I was particularly hopeful for
>> > http://tolstoy.newcastle.edu.au/R/help/06/07/30363.html) but I've either
>> > been misusing them, or they are not right for what I want to do.
>> >
>> > If anyone knows how to get points and lines in the same panel for the two
>> > different groups (probes/segments), I would love to hear about it.
>> >
>> > If you further know how to use the 'segment' plot in panels for the
>> > segments, I would really love to hear about it.
>>
>>

>> Well, panel.segments() draws segments, but you need your data in the
>> form (x1, y1, x2, y2) for that. With your setup, it's probably easier
>> to have lines with some NA-s inserted wherever you want line breaks.

That works perfectly! I was just planning on reformating the data, but this makes life even easier!

Thanks!

Aaron



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 Thu 10 Apr 2008 - 21:23:17 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 10 Apr 2008 - 21:30:31 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