Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I finally decided to ask directy to <a href="http://www.stat.auckland.ac.nz/~paul/" rel="nofollow">Paul Murrell</a>, the creator of grid and <a href="http://cran.r-project.org/web/packages/gridSVG/index.html" rel="nofollow">gridSVG</a>. He kindly provided some good advices and code which completely solved the problem with an approach similar to the advice from @mbq. I modified his code to write this function:</p> <pre><code>library(gridSVG) library(XML) animateTrellis &lt;- function(object, file='animatedSVG.svg', duration=.1, step=2, show=TRUE){ nLayers &lt;- dim(object) stopifnot(nLayers&gt;1) for (i in seq_len(nLayers)){ p &lt;- object[i] label &lt;- p$condlevels[[1]][i] ##Create intermediate SVG files g &lt;- grid.grabExpr(print(p, prefix=label), name=label) if (i==1){ ## First frame ga &lt;- animateGrob(g, group=TRUE, visibility="hidden", duration=duration, begin=step) } else if (i==nLayers){ ##Last Frame gg &lt;- garnishGrob(g, visibility='hidden') ga &lt;- animateGrob(gg, group=TRUE, visibility="visible", duration=duration, begin=step*(i-1)) } else { ##any frame gg &lt;- garnishGrob(g, visibility='hidden') gaV &lt;- animateGrob(gg, group=TRUE, visibility="visible", duration=duration, begin=step*(i-1)) ga &lt;- animateGrob(gaV, group=TRUE, visibility="hidden", duration=duration, begin=step*i) } grid.newpage() grid.draw(ga) fich &lt;- tempfile(fileext='.svg') gridToSVG(fich) ## Combine all if (i==1) { svgTop &lt;- xmlParse(fich) nodeTop &lt;- getNodeSet(svgTop, "//svg:g[@id='gridSVG']", c(svg="http://www.w3.org/2000/svg"))[[1]] } else { svgChildren &lt;- xmlParse(fich) node &lt;- getNodeSet(svgChildren, "//svg:g[@id='gridSVG']/*", c(svg="http://www.w3.org/2000/svg")) addChildren(nodeTop, node) } unlink(fich) } saveXML(svgTop, file=file) dev.off() if (show) browseURL(file) invisible(svgTop) } </code></pre> <p>Then I can produce the SVG file with animation:</p> <pre><code>p &lt;- xyplot(Sepal.Length~Petal.Length|Species, data=iris, layout=c(1, 1)) animateTrellis(p, file='iris.svg') </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload