我如何"交叉"没有名字的表格中的单元格

时间:2018-04-24 20:24:48

标签: r gtable

当我尝试调整vignettegridExtra的示例时,即

g <- tableGrob(iris[1:4, 1:3])
g <- gtable_add_grob(g,
        grobs = grobTree(
            segmentsGrob( # diagonal line ul -> lr
                x0 = unit(0,"npc"),
                y0 = unit(1,"npc"),
                x1 = unit(1,"npc"),
                y1 = unit(0,"npc"),
                gp = gpar(lwd = 2.0)),
            segmentsGrob( # diagonal line ll -> ur
                x0 = unit(0,"npc"),
                y0 = unit(0,"npc"),
                x1 = unit(1,"npc"),
                y1 = unit(1,"npc"),
                gp = gpar(lwd = 2.0))),
        t = 3, b = 3, l = 3, r = 3
    )
grid.draw(g)

Result of vignette code

到我的数据集,它没有行名或列名,不会出现交叉:

g <- tableGrob(iris[1:4, 1:3], rows=NULL, cols=NULL) # the only line that is changed
g <- gtable_add_grob(g,
        grobs = grobTree(
            segmentsGrob( # diagonal line ul -> lr
                x0 = unit(0,"npc"),
                y0 = unit(1,"npc"),
                x1 = unit(1,"npc"),
                y1 = unit(0,"npc"),
                gp = gpar(lwd = 2.0)),
            segmentsGrob( # diagonal line ll -> ur
                x0 = unit(0,"npc"),
                y0 = unit(0,"npc"),
                x1 = unit(1,"npc"),
                y1 = unit(1,"npc"),
                gp = gpar(lwd = 2.0))),
        t = 3, b = 3, l = 3, r = 3
    )
grid.draw(g)

slightly adapted

我被困住了。有什么帮助吗?

0 个答案:

没有答案