On Sun, Oct 17, 2010 at 10:01 AM, Coen van Hasselt <coenvanhass...@gmail.com> wrote: > Hi all, > > Using xyplot I want to print to Y variables (y1, y2) versus X, conditional > on the group. > How can I obtain a line (type="l") for one relationship (ie. y1 ~ x) and > points (type="p") for the other (y2 ~ x) ? > > library(lattice) > > # create some sample data > df<-data.frame(group=as.factor(c(rep("a",4), rep("b",4))), # grouping > variable for conditional plots > x=c(1:4,1:4), # x variable > y1=rnorm(4,0,1), # y1 > y2=rnorm(4,0,1)) # y2 > > > # Basically I want this plot, but then for y1~x points and for y2~x lines. > xyplot(y1+y2 ~ x|group, data=df) > > # This works, but then I get the same plot in the two grouping windows > because conditioning is lost in the panel function. > xyplot(y1+y2 ~ x|group, data=df, type="l", > panel=function(...){panel.xyplot(df$x,df$y1); > panel.xyplot(df$x,df$y1, type="l")})
Try: xyplot(y1+y2 ~ x|group, data=df, type=c("l","p"), panel=panel.superpose, distribute.type = TRUE) > Thanks for your help. > > Coen -- Prasenjit ______________________________________________ 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.