On Mon, Oct 26, 2009 at 12:19 PM, Ordaz, Sarah <ord...@upmc.edu> wrote:
> Hi,
> I'd like to clarify my previous posting.  See below - my updates are noted 
> with *s
> Thanks,
> Sarah Ordaz
> ord...@upmc.edu
>
> Hello,
>
> I am a newbie to the lattice package in R, and I'm trying to make a plot 
> using the xyplot function.  I have repeated
> measures data (2 conditions) for two different groups of subjects (teens and 
> adults).
>
> So far, I've made a basic graph using xyplot(y ~x, group=subnum, data=mydata, 
> type="b").
> *y is cognitive performance
> *x is pupil diameter
> *subnum = subject number
> *agegrp = age group (either teens or adults)
> *Here is "mydata", a sample data set:
>
> subnum  agegrp condition  pupil(x)   cognitive(y)
> 101           T         A          5.4            97
> 101           T        B          4.4            98
> 102           T         A          3.1            88
> 102           T         B          4.9            95
> 103           A         A          5.3            75
> 103           A         B          4.2            83
> 104           A         A          5.8            84
> 104           A         B           6.1            65
>
>
> Now I would like to make all the teens' lines one color and the adults' 
> another.  Additionally, I'd like to reformat the dots so
> that the points referencing condition A and condition B are different.  Can 
> you help me with this?


## you need to define an interaction, and then limit the number of
## colors to two (recycling ensures that the colors are associated
## with agegrp):

xyplot(y ~ x, group=interaction(agegrp, subnum),
       data=mydata, type="b", auto.key = TRUE,
       par.settings = simpleTheme(col = c("blue", "green")))

## for a more appropriate legend:

xyplot(y ~ x, group=interaction(agegrp, subnum),
       data=mydata, type="b", auto.key = list(text = c("A", "T")),
       par.settings = simpleTheme(col = c("blue", "green")))

## for different plotting characters, you need to do a bit more work:

xyplot(y ~ x, group=interaction(agegrp, subnum),
       data=mydata,
       par.settings = simpleTheme(col = c("blue", "green")),
       panel = panel.superpose,
       panel.groups = function(x, y, type, pch, ...) {
           panel.xyplot(x, y, type = "l", ...)
           panel.xyplot(x[1], y[1], type = "p", pch = 16, ...)
           panel.xyplot(x[2], y[2], type = "p", pch = 17, ...)
       })

-Deepayan

______________________________________________
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