Alinee la muesca en la posición superior / central fija, independientemente del tamaño
Tengo algunos grobs de mesa, algunos largos y otros cortos. Me gustaría dibujar estos en la parte superior / central de la página (con un pequeño margen).
Deesta respuesta, Obtuve un punto de partida útil, pero el posicionamiento depende de la altura de cada grob.
library(gridExtra)
# fake data
my_df <- data.frame(col1=rep('hello', 35), col2=round(rnorm(35), 3))
# list of grobs
tg <- list(tableGrob(my_df[1:30, ]), tableGrob(my_df[31:35, ]))
# this positions grobs at center top, but varies based on rows in table
tg[[1]]$vp <- viewport(x = 0.5,
y = unit(1,"npc") - 0.52 * grobHeight(tg[[1]]))
tg[[2]]$vp <- viewport(x = 0.5,
y = unit(1,"npc") - 0.52 * grobHeight(tg[[2]]))
# this one appears just below top, which is good
grid.newpage()
grid.draw(tg[[1]])
# this appears slightly closer to the top; desired outcome is to have column headers
# in same position as the previous one
grid.newpage()
grid.draw(tg[[2]])
He estado experimentando con diferentes parámetros para elviewport
llamada - p.
viewport(x = 0.5, y = unit(0.95, 'npc'), just=c('center', 'top'))
Pero no he tenido éxito. Cualquier ayuda apreciada!