0

I have a grobTable and a ggplot2 object and I want to plot them together using grid.arrange. The issue is that the resulting plot has always a whitespace above the two

library(grid)
library(gridExtra)
library(data.table)
library(ggplot2)

tmp = data.table(Group1 = c("C", "B", "A", "C", "B", "A", "C", 
                            "B", "A"), Group2 = c("C", "C", "C", "B", "B", "B", "A", "A", 
                                                  "A"), N = c(1949L, 7L, 403L, 64L, 13L, 73L, 347L, 13L, 2131L))

tmp2 = structure(c(0.84, 0.83, 0.84, 0.83, 0.83, 0.54, 0.09, 1, 0.39, 
                   0.09, 0.83, 0.86, 0.81, 0.82, 0.86), .Dim = c(5L, 3L), .Dimnames = list(
                     c("d", "p", "e", "x", "c"), c("h", "g", "p")))


tmp_plot = ggplot(data = tmp, aes(x =  Group1 , y = Group2))+
  geom_tile() +
  geom_text(aes(label = N)) +
  coord_fixed(ratio=1) +
  guides(fill=FALSE) +
  theme(plot.margin=unit(c(0,0,0,0), "mm"))

t <- tableGrob(tmp2, theme = ttheme_default(padding=unit(c(0, 0), "mm")))

grid.arrange(t, tmp_plot, ncol=2)

enter image description here

I have tried the following suggestions but nothing has worked so far: removing all the space between two ggplots combined with grid.arrange , R gridExtra 2.0.0: tableGrob vertical and horizontal padding

Any advice as to how to touch (and reduce) this space?

User2321
  • 2,952
  • 23
  • 46
  • You could move `tmp_plot` up, but I don't know if it's useful for your question. For example, by changing your `theme` input to `theme(plot.margin=unit(c(-50,0,0,0), "mm"))`. – bttomio Feb 28 '21 at 07:50
  • I think you can find the answer @ https://stackoverflow.com/questions/66589419/cropping-the-top-and-bottom-output-of-ggsave-from-grid-arrange-of-png-files – Grant Rogers Mar 19 '21 at 19:37

0 Answers0