使用 gridExtra 扩展 table

expanding table with gridExtra

如何增加 table 的大小,以便它占用所有可用的 space in..,即没有白色 space。

此外 - 如何删除 table 的行名称?

谢谢

dat = data.frame(x = c(1,2,4), y = c(12,3,5),z = c(5,6,7))
p =ggplot(dat, aes(x=x, y = y))+geom_point()+geom_line()
library(gridExtra)
t = tableGrob(dat)
rownames(t)  =NULL
t$widths <- unit(rep(1/ncol(t), ncol(t)), "npc")
grid.arrange(t, p,p,nrow = 1)

我更新了你的代码。重要的部分是 tableGrobrows = NULL 选项和 t$heights 的设置。您可能需要对此进行调整以获得符合您口味的东西。

library(gridExtra)
library(ggplot2)

dat <- data.frame(x = c(1, 2, 4), y = c(12, 3, 5), z = c(5, 6, 7))

p <- ggplot(dat, aes(x = x, y = y)) + 
  geom_point() + 
  geom_line()

t <- tableGrob(dat, rows = NULL) # notice rows = NULL

t$widths <- unit(rep(1 / ncol(t), ncol(t)), "npc")
t$heights <- unit(rep(1 / nrow(t), nrow(t)), "npc") # new

grid.arrange(t, p, p, nrow = 1)