How can I add a title to a tableGrob plot?

一曲冷凌霜 提交于 2019-11-30 20:26:11
baptiste

Not sure what the problem was, but here is a working example:

library(grid)
library(gridExtra)
library(gtable)

t1 <- tableGrob(head(iris))
title <- textGrob("Title",gp=gpar(fontsize=50))
padding <- unit(5,"mm")

table <- gtable_add_rows(
     t1, 
     heights = grobHeight(title) + padding,
     pos = 0)
table <- gtable_add_grob(
    table, 
    title, 
    1, 1, 1, ncol(table))

grid.newpage()
grid.draw(table)

Another option is:

library(gridExtra)
grid.arrange(top="Iris dataset", tableGrob(head(iris)))

You still might want to do some tweaking with the padding.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!