The update method of trellis plots allows one to modify a lattice plot after the initial call. But the update behaviour is more like replace than append. This differs from the ggplot2 idiom where each new layer is additive to what exists already. Is it possible to get this additive behaviour using lattice?
An example:
LL <- barchart(yield ~ variety | site, data = barley,
groups = year, stack = TRUE,
between=list(y=0.5),
scales = list(x = list(rot = 90)))
print(LL)

Now I want to add panel.text to the existing plot. Using update in the following way doesn’t work:
update(LL, panel=function(...){
args <- list(...); panel.text(args$x, args$y+2, round(args$y, 0))
})

I know that I can use update by specifying all of the layers in the panel function:
update(LL, panel=function(...){
args <- list(...)
panel.barchart(...)
panel.text(args$x, args$y+2, round(args$y, 0))
})
This will work, but requires that I know what is already in the lattice plot – or that I refactor my code quite substantially.
Question: Is there a way of adding to the existing panel in update.trellis?
See
layerfrom thelatticeExtrapackage.