is there a comfortable way to connect points only if the connection has a positive slope? (otherwise the function should behave exactly as 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",...)
}
)
so the result shoud be a plot like this, but without crossed lines:
Thank you Christof
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, ...)
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With