I am showing two alternatives, both from the HH package.
install.packages("HH")

The first one does essentially what you request,

smithdata <- src[c("x", "trt")]
smithdata$timefactor <- factor(src$time)
position(smithdata$timefactor) <- as.numeric(levels(smithdata$timefactor))
position(smithdata$trt) <- c(7, 17)
smithdata


intxplot(x ~ timefactor, data=smithdata, groups=trt, se=TRUE, ylim=c(-1,9),
         cv=1, main="this is your graph, with critical value=1.00")

intxplot(x ~ timefactor, data=smithdata, groups=trt, se=TRUE, ylim=c(-1,9),
         main="this is your graph with more typical critical value=1.96")


## I don't know what the red and green dots on your sample graph signify, so
## I didn't attempt to reproduce them.

## When I look at interaction plots, I normally want to look at both
## sequences, interchanging the role of the x-variable and the
## trace-variable.  Therefore I recommend

interaction2wt(x ~ timefactor*trt, data=smithdata, simple=TRUE)

Rich


On Tue, May 29, 2012 at 4:42 PM, John Smith <zmr...@gmail.com> wrote:

> Dear R users,
>
> I am trying to use xyplot to draw group mean and CI. The following is the
> sample code. But I want:
>
>   1. Use different colors and symbols to draw individual points, CI and
>   the lines connect group means from different time points;
>   2. Add jitters to x axis to allow CIs not be overlapped
>
> Could anyone modify the attached code to achieve this?
>
> Thanks
>
>
>
>
>
> library(lattice)
> set.seed(123)
> src <- data.frame(time = rep(c(1, 6, 24), rep(6,3)), trt =
> rep(rep(c('C','T'), each=3), 3))
> src <- transform(src, x=sqrt(time)+2*(trt=='C')+rnorm(18), trt =
> ordered(trt, levels=c('C','T')))
> src <- src[-5,]
> src$m <- ave(src$x, src[c('time','trt')], FUN = mean)
> src$sd <- ave(src$x, src[c('time','trt')], FUN = sd)
> src$n <- ave(src$x, src[c('time','trt')], FUN = length)
> src <- transform(src, se = sd/sqrt(n))
> src <- transform(src, cl=m-se, cu=m+se)
>
> prepanel.ci <- function(x, y, ly, uy, subscripts, ...)
>  {
>    x <- as.numeric(x)
>    ly <- as.numeric(ly[subscripts])
>    uy <- as.numeric(uy[subscripts])
>    list(ylim = range(y, uy, ly, finite = TRUE))
>  }
>
> panel.ci <- function(x, y, ly, my, uy, subscripts, ...)
>  {
>    x <- as.numeric(x);    y <- as.numeric(y);  my <-
> as.numeric(my[subscripts])
>    ly <- as.numeric(ly[subscripts]);  uy <- as.numeric(uy[subscripts])
>    panel.xyplot(x, y, ...)
>    panel.arrows(x, ly, x, uy, length = 0.25, unit = "native", angle = 90,
> code = 3)
>    panel.lines(x, my)
>  }
>
> par.settings <- list(superpose.symbol = list(col = c("red", "green",
> "blue"),
>                       fill = c("red", "green", "blue"), pch=15:17),
>                      superpose.line = list(col = c("red", "green",
> "blue")))
> windows(width=10.67, height=6.60)
> xyplot(x ~ time, xlab="Time", ylab="X", groups=trt, data=src, trt=src$trt,
>       ly = src$cl, uy = src$cu, mx = src$time, my = src$m, type="p",
>       prepanel = prepanel.ci, panel = panel.superpose, panel.groups =
> panel.ci,
>       auto.key = list(space = "top",  points = TRUE, lines = TRUE,
> columns=2),
>       par.settings = par.settings)
>
>        [[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<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