[R] xyplot problem
Kevin E. Thorpe
kevin.thorpe at utoronto.ca
Thu Jun 15 17:39:24 CEST 2006
Marc Bernard wrote:
> Dear all,
>
> I have created the following data (that you can run) in order to explain my problem:
>
> y <- rep(c(1,2), 8)
> id <- rep(1:8,each=2)
> x1 <- rep(c("-a","+a"), each = 8)
> x2 <- rep(c("-b","+b"), each = 2, times = 4)
> x3 <- rep(c("-c", "+c"), each = 4,2)
> df <- data.frame(cbind(id,y,x1,x2,x3))
>
> If I do:
>
> xyplot(y~ x3|x1*x2,data=df,groups=id,type = "b")
>
> then my id's are joined by lines which is what I want. However when I wanted to add an horizontal line for each panel by using "panel.abline" the lines disapears, i.e.
>
> xyplot(y~ x3|x1*x2,data=df,groups=id,type = "b",panel=function(x,y)
> {
> panel.xyplot(x,y)
> panel.abline(h=1.5)
> }
> )
>
>
> I would be grateful if someone can tell me how can I correct the second statement in order to have horizontal lines for each panel and each id are joined by lines.
>
> Thank you,
>
> Bernard,
This appears to work for me.
xyplot(y~ x3|x1*x2,data=df,groups=id,type = "b",
panel=function(x,y,groups,...) {
panel.superpose(x,y,groups,...)
panel.abline(h=1.5)})
--
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Department of Public Health Sciences
Faculty of Medicine, University of Toronto
email: kevin.thorpe at utoronto.ca Tel: 416.946.8081 Fax: 416.946.3297
More information about the R-help
mailing list