【问题标题】:expanding table with gridExtra使用 gridExtra 扩展表格
【发布时间】:2017-03-09 05:03:49
【问题描述】:

如何增加表格的大小以使其占用所有可用空间......即没有空白。

另外,如何删除表格的行名?

谢谢

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)

【问题讨论】:

  • 那删除了行名但是如何扩展情节?
  • 您能否更明确地说明您要删除哪些空白?只是在侧面吗?您是否也希望它占据 100% 的高度?并且只是将空格移动到单元格本身中?
  • 是的,占据 100% 的宽度和 100% 的高度

标签: r ggplot2 gridextra


【解决方案1】:

我更新了你的代码。重要的部分是rows = NULL 选项到tableGrobt$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)

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    相关资源
    最近更新 更多