block by timelyportfolio 9d7f106c11682f5bb5fb

r plot.zoo animated construction with svg+js using vivus.js

Full Screen

Another quick example of animated chart construction in R using vivus.js and SVGAnnotation. This time we use a plot.zoo chart as our source.

Also, see this first simple example.

replicate/extend

Code is here.

code.R

library(xts)
library(htmltools)
library(rvest)
library(pipeR)
library(SVGAnnotation)

svgPlot(plot.zoo(
  as.xts(sample_matrix)
  ,auto.grid=F
  ,bty='n'
))  %>>%
  saveXML %>>%
  html %>>%
  html_node("svg") %>>%
  addAttributes(
    id = "rplot"
  ) %>>%
  (
    tagList(
      . %>>% saveXML %>>% HTML
      ,tags$script(
        "new Vivus('rplot',{type: 'delayed',start:'autostart',delay:0,duration:500})"
        #"new Vivus('rplot',{type: 'oneByOne',start:'autostart',delay:0,duration:500})"
      )
    )
  ) %>>%
  attachDependencies(
    htmlDependency(
      name="vivus"
      ,version="0.1"
      ,src=c("href"=
               "http://maxwellito.github.io/vivus/dist"
      )
      ,script = "vivus.min.js"
    )
  ) %>>%
  html_print #%>>%
#  rCharts:::publish_.gist(
#    description = "r plot.zoo animated construction with svg+js using vivus.js"
#    ,id = NULL
#  )