Animated scatterplot from two stock quotes charts

Originally I had the idea for this little project (still can’t find a name or description for it) when dealing with the stock quotes correlations. The tool I came up with shows the scatterplot for two stock quotes charts and the respective Pearson correlation coefficient. I wanted to see if one can tell from the scatterplot and the coefficient how two stocks relate to each other. I didn’t take this investigation much further than the visualization and some pondering about patterns shown in the scatterplots.

Delayed correlation

One thought that entered my mind was that of course it might be the case that two stocks relate very strongly but neither the coefficient nor the scatterplot would reveal that because the relation is delayed. Bascially this is the fundamental motivation behind animating a scatterplot for two stocks with one stock chart moving in time. Again (like with the stock correlations article) the whole project turned into a more technical direction applying ggplot2 and ffmpeg for the first time. Still I think the animations look pretty and might be insightful on how scatterplots relate to the underlying data.

I am going to write more about ggplot2 and ffmpeg in the near future. Also I will soon post the R code I used for this article.