vertical alignment of gridExtra tableGrob (R grid graphics/grob)

后端 未结 1 1924
滥情空心
滥情空心 2020-12-21 01:14

Having some trouble aligning a grid graphics object -- have read all the docs I can find, including the Murrell book, but no success. I think what I\'m trying to do is pret

相关标签:
1条回答
  • 2020-12-21 01:57

    try this,

    enter image description here

    library(gridExtra)
    justify <- function(x, hjust="center", vjust="center", draw=TRUE){
      w <- sum(x$widths)
      h <- sum(x$heights)
      xj <- switch(hjust,
                   center = 0.5,
                   left = 0.5*w,
                   right=unit(1,"npc") - 0.5*w)
      yj <- switch(vjust,
                   center = 0.5,
                   bottom = 0.5*h,
                   top=unit(1,"npc") - 0.5*h)
      x$vp <- viewport(x=xj, y=yj)
      if(draw) grid.draw(x)
      return(x)
    }
    
    g <- tableGrob(iris[1:3,1:2])
    grid.newpage()
    justify(g,"right", "top")
    
    0 讨论(0)
提交回复
热议问题