Here's a lattice solution using some faked data.

library(lattice)
testdat <- data.frame(time = rep(rep(1:10, each = 4), 8),
                       y = rnorm(320),
                       gender = factor(rep(rep(c('F', 'M'), each = 80), 2)),
                       grade = factor(rep(c('1-3', '4-6'), each = 160)),
                       gp = factor(rep(rep(c('Control', 'Intervention'),
each = 40), 4)))
testmn <- aggregate(y ~ time + gp + gender + grade, data = testdat, FUN =
mean)
xyplot(y ~ time | gender * grade, groups = gp, data = testmn,
     type = c('p', 'l'), auto.key = list(space = 'top', lines = TRUE,
     points = FALSE, columns = 2))

I have four replicate observations at each of ten times for eight
combinations
of gender, grade level and treatment group. aggregate() is used to average
the four observations at each time point, and then point/line graphs of
average response vs. time in each treatment is plotted for each gender
and grade level combination.

I hope I caught the essential characteristics of what you wanted.

Dennis

On Fri, Aug 13, 2010 at 2:58 PM, Robin Jeffries <rjeffr...@ucla.edu> wrote:

> Hello,
>
> I need to plot the means of some outcome for two groups (control vs
> intervention) over time (discrete) on the same plot, for various subsets
> such as gender and grade level. What I have been doing is creating all
> possible subsets first, using the aggregate function to create the means
>  over time, then plotting the means over time (as a simple line plot with
> both control & intervention on one plot) for one subset. I then use par()
> and repeat this plot for each gender x grade level subset so they all
> appear
> on one page.
>
>
> This appears to me to be very similar to an xyplot, something like
>  mean(outcome) ~ gender + gradelevel. However, I can't figure out how I
> could get both control and intervention lines in the same plot.
>
> Any suggestions? What i'm doing now -works-, but just seems to be the long
> way around.
>
> -Robin
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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