Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move subplots closer together with R

Tags:

r

I am trying to move subplots closer together with R.

What I am doing is basically not important, but just for the sake of fast reproducing, here is the code:

library(igraph)
library(plyr)

g<-graph.ring(10)
setEPS()
postscript( 'out.eps', horizontal=F, onefile=F, paper="special", fonts=c("serif", "Palatino"))

par( mfrow = c( 1, 5 ) )
for (i in 1:5){
  plot(g)
  title(main='title', cex.main=1.2)
}

dev.off() 

and as an output I am getting:enter image description here

I know that I can organize it in a 2x3 layout, not 1x5, but this is not important. The thing is, that there is a lot of free space between each subplots, and I would like to place them as tight as possible.

Is there a way to achieve it?

P.S. this question sounds like relevant, but in fact it is not.

like image 475
Salvador Dali Avatar asked Apr 24 '13 16:04

Salvador Dali


2 Answers

You just need to add:

par(mar = c(5,0,4,0))

to adjust the margins of each plot. There is another way of adjusting the margins by setting mai

like image 154
joran Avatar answered Sep 19 '22 16:09

joran


What I usually do is use the omi ('c(bottom, left, top, right)') and plt ('c(x1, x2, y1, y2)') arguments in par. omi sizes the outer margins in inches and plt gives the coordinates of the plot region as a fraction of the figure region. Use ?par for a more detailed explanation and more arguments.

par(mfrow = c(2,3), omi=c(0.5,0.3,0,0), plt=c(0.1,0.9,0,0.7))
like image 31
Arhopala Avatar answered Sep 21 '22 16:09

Arhopala