title: in R : embedding a bitmap by link reference into a SVG image
body: <p>I would like, in R, to embed a bitmap image <em>by link reference</em> into a SVG plot image.</p>
  
  <p>Images may be included in an SVG by <a href="http://www.w3.org/TR/SVG/struct.html#ImageElementHrefAttribute" rel="nofollow">link reference</a>, or even <a href="http://en.wikipedia.org/wiki/Data_Uri" rel="nofollow">data</a>, for example:</p>
  
  <pre><code>&lt;image x="50" y="50"  width="100" height="100" xlink:href="myimage.png"&gt;
  &lt;image x="50" y="50"  width="100" height="100" xlink:href="data:image/png;base64,[data]"&gt;
  </code></pre>
  
  <p>My objective is to reduce the size and complexity of the SVG image files I am generating (My plots have about 10⁶ points: that's a 250Mb SVG file requiring 8Gb RAM for editing with <a href="http://inkscape.org/" rel="nofollow">inkscape</a> ). I was thinking generating most of the plot as a bitmap image (say PNG), and some key elements of the plot (the ones that will later have to be edited by hand) as an SVG image, and then combine both images using the trick I've just described above.</p>
  
  <p>I have tried using the pixmap library, but the bitmap is added as a vectorial image, dot by dot, which would not reduce the overall file size:</p>
  
  <pre><code>library(pixmap)
  svg("image.svg")
  x &lt;- -5:5 ; y &lt;- x^2 ;  plot(x,y)
  bitmap &lt;- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
  addlogo(bitmap, px=c(-3, 3), py=c(0, 6), asp=1)
  dev.off()
  </code></pre>
  
  <p>Any thoughts on the way to do this would be more than welcome. </p>
  
  <p>Many thanks.</p>