用gridExtra扩展表(expanding table with 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)How do increase the size of the table so that it take up all of the available space in..i.e so there's no white space.
Also- how do you remove row names of the table?
Thank you
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)最满意答案
我更新了你的代码。 重要的部分是tableGrob的rows = NULL选项和t$heights tableGrob的设置。 您可能需要调整一下以获得符合您口味的东西。
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)I updated your code. The important parts are the rows = NULL option to tableGrob and the setting of t$heights. You probably need to tweak this to get something to your taste.
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)更多推荐
发布评论