How can I add a title to a tableGrob plot?

前端 未结 2 434
鱼传尺愫
鱼传尺愫 2021-01-04 22:42

I have a table, and I want to print a title above it:

t1 <- tableGrob(top_10_events_by_casualties, cols=c(\"EVTYPE\", \"casualties\"), rows=seq(1,10))
gri         


        
2条回答
  •  情书的邮戳
    2021-01-04 23:32

    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)
    

提交回复
热议问题