title: igraph: positioning labels and removing empty space in grid layout
body: <p>I want to make a function which plots directed graphs with vertices aligned and adds some text below each vertex, i.e. something like the example plot below. The plotting function should be able to handle pie graphs as vertices, so I have used <code>igraph</code> package in R.</p>
  
  <pre><code>adjm &lt;- matrix(c(0,1,0,1,
                   0,0,1,1,
                   0,0,0,1,
                   0,0,0,0), nrow=4, byrow=TRUE)
  
  g1 &lt;- graph.adjacency(adjm, mode="directed")
  
  values &lt;- lapply(1:4, function(x) sample(1:4,4))
  
  windows(width=7, height=3.5)
  
  plot(g1, layout=layout.grid(g1, width=4), 
       vertex.shape="pie", vertex.pie=values,
       vertex.pie.color=list(heat.colors(4)),
       edge.curved=TRUE,
       vertex.label=LETTERS[1:4], vertex.size=50,
       vertex.label.dist=5, vertex.label.degree=pi/2, 
       edge.label=1:5, rescale=FALSE, 
       xlim=c(-0.2,3.5), ylim=c(0,0.5))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/GSX4G.png" alt="enter image description here"></p>
  
  <p>I have two problems.</p>
  
  <ol>
  <li><p>Why is it that the longer the vertex label, the longer the distance to the vertex centre as in the following example? Can I force them to appear at the same level without manually finding and defining them the right distance?</p>
  
  <pre><code>windows(width=7, height=3.5)
  
  plot(g1, layout=layout.grid(g1, width=4), 
       vertex.shape="pie", vertex.pie=values,
       vertex.pie.color=list(heat.colors(4)),
       edge.curved=TRUE,
       vertex.label=c("A", "AA", "AAAA", "AAAAAA"), vertex.size=50,
       vertex.label.dist=5, vertex.label.degree=pi/2, 
       edge.label=1:5, rescale=FALSE, 
       xlim=c(-0.2,3.5), ylim=c(0,0.5))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/HSoNa.png" alt="enter image description here"></p></li>
  <li><p>How to remove empty space when plotting aligned plots? If I make a horizontal graph it will be placed at the bottom of the window with a lot of empty space. The flatter the image, the smaller the graph, as in the third plot. (It seems that the size of the graph is determined such that the plot would fit in any position, vertical or horizontal.)</p>
  
  <pre><code>plot(g1, layout=layout.grid(g1, width=4), 
       vertex.shape="pie", vertex.pie=values,
       vertex.pie.color=list(heat.colors(4)),
       edge.curved=TRUE,
       vertex.label=c("A", "AA", "AAAA", "AAAAAA"), vertex.size=20,
       vertex.label.dist=2, vertex.label.degree=pi/2, edge.label=1:5)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/3Uog7.png" alt="enter image description here">
  I can write argument <code>asp=0</code> to keep the vertices the right size in a flatter window but the automatic curvatures and the positions of the vertex labels change. I can manually tweak negative upper margin, label distances, and edge curvature, but of course this is not a solution for a generic function. The best result so far was the result of <code>rescale=FALSE</code> as in the code for the first plot, but the edge curvatures are still too small and with larger vertices they get behind the vertices completely. (Also, the problem with varying vertex label distances still remains.) Direct use of <code>autocurve.edges</code> is not giving me any curvature. Any ideas of what to try next?</p></li>
  </ol>