0

I am trying to reduce horizontal space between figures in grid.arrange. I want to minimize white space as much as possible. The component figures are produced by the gplot function in the sna package, which uses base graphics. This function seems to produce plots with wide left and right margins (because the plot area is approximately square, in a rectangular plotting space there is extra space on these margins). I have tried reducing the plot margins to 0 in par, but this does not seem to have any effect. I can I reduce the component plot margins/whitespace to a minimum in this example?

library(sna)
library(gridExtra)
library(gridGraphics)
library(ggplotify)

par(mar = c(7,0,1,0))
m <- list()
for(i in 1:4){
  gplot(rgraph(10, tprob=.3))
  grid.echo()
  m[[i]] <- grid.grab()
}

#grid.arrange(m, ncol = 2)
#lapply(m, class)

grid.arrange(m[[1]], m[[2]], m[[3]], m[[4]], ncol = 2)

I have also tried increasing the plot width and height itself with:

options(repr.plot.width=10, repr.plot.height=10)

but this does not seem to have any effect.

tvg
  • 388
  • 2
  • 13
  • Are all these packages really required for a reproducible example? Also note that there is a [difference between base and grid graphics](https://stackoverflow.com/questions/51013391/whats-the-difference-between-ggplot-and-basic-plot-in-r) in R. Things like `par()` only work for base graphics and ggplot functions use grid graphics. The margins you see are also dependent on your graphics device height and width but that's not specified here. – MrFlick Dec 18 '19 at 15:49
  • loading grid is not required (though gridGraphics will load it anyway) - edited that. Everything else is required. I get the difference between base and grid graphics. Maybe the problem is trying to combine them but I use the sna package for my network plotting and I'm not aware of another solution to combine plots, other than grid.arrange. I tried changing the width and height of the plotting devide using dev.new but also see no effect – tvg Dec 18 '19 at 16:03

0 Answers0