user3022875
user3022875

Reputation: 9018

expanding table with gridExtra

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)

Upvotes: 1

Views: 275

Answers (1)

Johan Larsson
Johan Larsson

Reputation: 3694

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

Upvotes: 2

Related Questions