【发布时间】:2011-10-04 14:47:23
【问题描述】:
trellis plots 的update 方法允许在第一次调用后修改lattice plot。但是update 的行为更像是替换而不是追加。这与ggplot2 习惯用法不同,其中每个新层都是对已经存在的内容的添加。是否可以使用lattice 获得这种附加行为?
一个例子:
LL <- barchart(yield ~ variety | site, data = barley,
groups = year, stack = TRUE,
between=list(y=0.5),
scales = list(x = list(rot = 90)))
print(LL)
现在我想将panel.text 添加到现有绘图中。按以下方式使用update 不起作用:
update(LL, panel=function(...){
args <- list(...); panel.text(args$x, args$y+2, round(args$y, 0))
})
我知道我可以通过在面板函数中指定所有层来使用update:
update(LL, panel=function(...){
args <- list(...)
panel.barchart(...)
panel.text(args$x, args$y+2, round(args$y, 0))
})
这会起作用,但需要我知道 lattice 图中已经存在的内容 - 或者我需要大量重构我的代码。
问题:有没有办法添加到update.trellis中的现有面板?
【问题讨论】: