Lattice graph with segments
On Saturday 04 December 2004 14:40, Tim Churches wrote:
Andrew Robinson wrote:
Ruud,
try something like the following (not debugged, no coffee yet):
xyplot(coupon.period ~ median, data=prepayment,
subscripts=T,
panel=function(x,y,subscripts,...){
panel.xyplot(x,y)
panel.segments(deel1$lcl[subscripts], deel$ucl[subscripts])
}
)
Not quite:
library(lattice)
prepayment <- data.frame(median=c(10.89,12.54,10.62,8.46,7.54,4.39),
ucl=c(NA,11.66,9.98,8.05,7.27,4.28),
lcl=c(14.26,13.34,11.04,8.72,7.90,4.59),
coupon.period=c('a','b','c','d','e','f'))
xyplot(coupon.period ~ median, data=prepayment,
subscripts=T,
panel=function(x,y,subscripts,...){
panel.xyplot(x,y)
panel.segments(prepayment$lcl[subscripts],
prepayment$ucl[subscripts]) }
)
throws the error:
Error in max(length(x0), length(x1), length(y0), length(y1)) :
Argument "x1" is missing, with no default
Right. Also, to make the resulting object self-contained (i.e. not
dependent on having a particular data frame in the scope), I would do
something similar to (either one of):
with(prepayment,
xyplot(coupon.period ~ median,
lcl = lcl, ucl = ucl,
panel=function(x, y, subscripts, lcl, ucl, ...) {
panel.xyplot(x, y, ...)
panel.segments(lcl[subscripts], as.numeric(y),
ucl[subscripts], as.numeric(y), ...)
}))
xyplot(coupon.period ~ median, data = prepayment,
lcl = prepayment$lcl, ucl = prepayment$ucl,
panel=function(x, y, subscripts, lcl, ucl, ...) {
panel.xyplot(x, y, ...)
panel.segments(lcl[subscripts], as.numeric(y),
ucl[subscripts], as.numeric(y), ...)
})
Deepayan