> Does using > > df = df[order(df$type,df$set,df$x),] > > before calling xyplot fix the problem?
Thank you very much for your suggestion. It does make the lines open, but unfortunately it mixes different id together. With the new ordering the plot looks something like this: (x=-10, y_id1) -> (x=-10, y_id2) -> (x=-9.5, y_id1) -> (x=-9.5, y_id2)... I tried many combinations. It seems that when df$id is sorted before df$dx the plot has a loop. In the other case the ids get mixed. By the way, my previous example had wrong id labels. This should be right: library(lattice) x1 <- seq(-10, 10, 0.5) x2 <- seq(-10, 10, 0.1) df <- data.frame(x=x1, y=sin(x1), id='1a_s1', type='A', set='s1') df <- rbind(df, data.frame(x=x1, y=cos(x1), id='1b_s1', type='B', set='s1')) df <- rbind(df, data.frame(x=x1, y=3*sin(2*x1), id='2a_s1', type='A', set='s1')) df <- rbind(df, data.frame(x=x1, y=3*cos(2*x1), id='2b_s1', type='B', set='s1')) df <- rbind(df, data.frame(x=x2, y=sin(x2), id='1a_s2', type='A', set='s2')) df <- rbind(df, data.frame(x=x2, y=cos(x2), id='1b_s2', type='B', set='s2')) df <- rbind(df, data.frame(x=x2, y=3*sin(2*x2), id='2a_s2', type='A', set='s2')) df <- rbind(df, data.frame(x=x2, y=3*cos(2*x2), id='2b_s2', type='B', set='s2')) p=xyplot(y~x|set, df, type='l', group=type, auto.key = list(points = FALSE, lines = TRUE, columns = 2)) print(p) ______________________________________________ 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.