title: Icons as x-axis labels in R - ggplot2
body: <p>(This is an extension to the question <a href="https://stackoverflow.com/questions/29922673/icons-as-x-axis-labels-in-r">Icons as x-axis labels in R</a>. It looks for a <em>ggplot</em> solution instead of a <em>plot</em> one. Since <code>ggplot</code> is based on <em>grid</em> and <code>plot</code> is based on <em>graphics</em>, the approach is very different)</p>
  
  <p>I would like to plot something like this <a href="http://wwwconference.org/www2008/papers/pdf/p665-adamic.pdf" rel="nofollow noreferrer">(from this paper)</a> where icons, in this case small graphs, are used as tick labels.</p>
  
  <p><img src="https://i.stack.imgur.com/I7Id8.png" alt="enter image description here"></p>
  
  <p>The accepted answer from the original question is:</p>
  
  <pre><code>library(igraph)    
  npoints &lt;- 15
  y &lt;- rexp(npoints)
  x &lt;- seq(npoints)
  
  # reserve some extra space on bottom margin (outer margin)
  par(oma=c(3,0,0,0))
  plot(y, xlab=NA, xaxt='n',  pch=15, cex=2, col="red")
  lines(y, col='red', lwd=2)
  
  # graph numbers 
  x = 1:npoints   
  
  # add offset to first graph for centering
  x[1] = x[1] + 0.4
  x1 = grconvertX(x=x-0.4, from = 'user', to = 'ndc')
  x2 = grconvertX(x=x+0.4, from = 'user', to = 'ndc')
  
  for(i in x){  
  
    print(paste(i, x1[i], x2[i], sep='; '))
  
    # remove plot margins (mar) around igraphs, so they appear bigger and 
    # `figure margins too large' error is avoided
    par(fig=c(x1[i],x2[i],0,0.2), new=TRUE, mar=c(0,0,0,0))
    plot(graph.ring(i), vertex.label=NA)  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/h8cJ8.png" alt="enter image description here"></p>
  
  <p>How can we make a similar plot using <strong>ggplot</strong>?</p>
  
  <p>This is the closer I get:</p>
  
  <pre><code>library(ggplot2)
  library(grImport)
  library(igraph)
  
  npoints &lt;- 5
  y &lt;- rexp(npoints)
  x &lt;- seq(npoints)
  
  pics  &lt;- vector(mode="list", length=npoints)
  for(i in 1:npoints){
    fileps &lt;- paste0("motif",i,".ps")
    filexml &lt;- paste0("motif",i,".xml")
  
    # Postscript file
    postscript(file = fileps, fonts=c("serif", "Palatino"))
    plot(graph.ring(i), vertex.label.family="serif", edge.label.family="Palatino")
    dev.off()
  
    # Convert to xml accessible for symbolsGrob
    PostScriptTrace(fileps, filexml)
    pics[i] &lt;- readPicture(filexml)
  }
  xpos &lt;- -0.20+x/npoints
  my_g &lt;- do.call("grobTree", Map(symbolsGrob, pics, x=xpos, y=0))
  qplot(x, y, geom = c("line", "point")) + annotation_custom(my_g, xmin=-Inf, xmax=Inf, ymax=0.4, ymin=0.3)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/QAkTu.png" alt="enter image description here"></p>