Search code examples
rcandlestick-chartgooglevis

Animating googleVis plots


I really like how motion charts look here but I'd like to animate some of the other plots (rather than just the scatterplot chart).

For example, is it possible to animate a candlestick plot?


Solution

  • In spite of your question, Ill answer as if you didn't care about using googleVis and just wanted to make candlestick charts with animation without regard to style. (mostly because I have terrible style, and because googleVis charts are made with non-R tools)

    install.packages("quantmod")
    install.packages("animation")
    library(quantmod)
    library(animation)
    
    getSymbols("GS") 
    
    chartSeries(GS) 
    
    
    ani.options(interval = 0.05)
    saveGIF({
    
        for(i in 1:20){  
        candleChart(GS,multi.col=TRUE,theme='white',yrange=c(0,1200));
          GS = GS+rnorm(3,50)  ; # replace this with something interesting.
    }
    
    }, movie.name = "animation.gif", img.name = "Rplot", convert = "convert", 
        cmd.fun = system, clean = TRUE)
    

    A moving candlestick chart