Embed animations using SciAnimator in knitr

We can set the package option animation.fun to hook_scianimator so that multiple plots in a chunk can be animated via the SciAnimator library.

library(knitr)
opts_knit$set(animation.fun = hook_scianimator)

You have to embed the jQuery and SciAnimator libraries in the HTML header (between <head> and </head>), even though some browsers can tolerate it if you insert a style sheet after <body>.

Here comes a test of the Brownian motion:

n = length(palette())
x = rnorm(n); y = rnorm(n)
for (i in 1:20) {
  x = x + rnorm(n); y = y + rnorm(n)
  plot(x, y, xlim=c(-10, 10), ylim=c(-10,10), pch=19, col=1:n, cex=2)
}

There are many other examples at http://vis.supstat.com.



Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on May 20, 2021, 5:08 p.m.