如何使用gtable_add_grob()不“添加" [英] How to use gtable_add_grob() does not 'add'

查看:158
本文介绍了如何使用gtable_add_grob()不“添加"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下面的图在6个面板中不显示数字(g;通过textGrob(label=g))指定)?如果仅使用文本grob,这也可以使用,但是文本grob和矩形grob似乎并不那么容易.不幸的是,gtable_add_grob的帮助页面没有提供太多帮助...

Why does the following plot not display the numbers (g; specified via textGrob(label=g))) in the 6 panels? If I use the text grob only, this also works, but a text grob and a rectangular grob seem to be not so easy. Unfortunately the help page of gtable_add_grob does not give a lot of help...

require(gtable)
base <- gtable(widths=unit(rep(1, 2), "null"),
               heights=unit(rep(1, 3), "null"))
g <- 1
for(i in 1:3) {
    for(j in 1:2) {
        base <- gtable_add_grob(base, list(rectGrob(gp=gpar(fill="#FF000088")), textGrob(label=g)), i, j)
        g <- g+1
    }
}
grid.draw(base)

推荐答案

抢手需要使用不同的名称:

The grobs need different names:

base <- gtable_add_grob(base, 
          list(rectGrob(gp=gpar(fill="#FF000088")), textGrob(label=g)), i, j,
          name=1:2)

这篇关于如何使用gtable_add_grob()不“添加"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆