r - 是否可以更新 R 中的晶格面板?

标签 r plot lattice

update trellis的方法plots 允许修改 lattice在初始调用后绘制。但是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)

enter image description here

现在我想添加 panel.text到现有的情节。使用 update以下方式不起作用:
update(LL, panel=function(...){
           args <- list(...); panel.text(args$x, args$y+2, round(args$y, 0))
         })

enter image description here

我知道我可以使用 update通过在面板函数中指定所有图层:
update(LL, panel=function(...){
           args <- list(...)
           panel.barchart(...)
           panel.text(args$x, args$y+2, round(args$y, 0))
         })

这会起作用,但需要我知道 lattice 中已有的内容情节 - 或者我相当大地重构了我的代码。

问题:有没有办法添加到 update.trellis 中的现有面板中? ?

最佳答案

layer来自 latticeExtra 包裹。

library(lattice)
library(latticeExtra)
LL <- barchart(yield ~ variety | site, data = barley,
        groups = year, stack = TRUE,
        between=list(y=0.5),
        scales = list(x = list(rot = 90)))
LL + layer(panel.text(x, y, round(y, 0), data=barley))

result of code

关于r - 是否可以更新 R 中的晶格面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7649737/

相关文章:

r - 如何用ggplot绘制回归线?

python - Jupyter 笔记本 rpy2 Rmagics : How to set the default plot size?

r - 将参数 tibble 映射到使用 pmap 分配的函数会生成一个列表,而不是环境中的对象(根据需要)

r - 将列值分类到具有特定输出的新列中

r - R 中的 xgboost() 错误

r - 如何在点阵图中将不同的符号分配给不同的组?

R:来自矩阵的多个晶格水平图

r - 在列表上使用 purrr 在不同的列上进行变异

python - 如何将此 csv 数据转换为条形图?

r - 在多条线上拆分绘图轴标签