lattice,仅当连接具有正斜率时才连接点

lattice, connect points only if the connection has a positive slope

仅当连接具有正斜率时,是否有一种舒适的连接点的方法? (否则该函数的行为应与 xyplot(...) 完全相同)

library(lattice)

dat <- data.frame(x=1:10,y=sample(1:10))

xyplot(y ~ x, data=dat,
       panel = function(x, y,...) { 
         panel.xyplot(x, y, type="o",...)
       }
)

所以结果应该是这样的情节,但没有交叉线:

谢谢 克里斯托夫

dat <- dat[order(dat[, "x"]),]
dat$group <- cumsum(c(1, diff(dat$y) < 0))


xyplot(y ~ x, data = dat, groups = group,
       panel = function(x, y,...) { 
         panel.xyplot(x, y, type = "o", col = trellis.par.get("plot.line")$col, ...)
       }
)