2017-03-08 54 views
0

如何增加表格的大小以便佔用所有可用空間,因此沒有空白區域。使用gridExtra擴展表格

另外 - 你如何刪除表的行名?

謝謝

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) 
+0

,消除行名稱,但如何擴大情節? – user3022875

+0

你能更清楚地知道你想刪除什麼空白嗎?它只是在兩側?你是否希望它佔據高度的100%?只要將空白移入單元格本身? – MrFlick

+0

是佔用100%的寬度和100%的高度 – user3022875

回答

1

我更新了你的代碼。重要的部分是rows = NULL選項tableGrob和設置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) 

Imgur