用gridExtra扩展表(expanding table with gridExtra)

编程入门 行业动态 更新时间:2024-10-12 08:25:09
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)

Imgur

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)

Imgur

更多推荐

本文发布于:2023-08-05 00:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gridExtra   expanding   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!