Plotting Time-lapse Data with ggplot2

Matthew Berginski
1 min readJul 14, 2016

--

Plotting time-lapse data with confidence intervals in base-R graphics can be a bit difficult. The base-R graphics functions aren’t necessarily aware of the extents of the confidence intervals, so normally the min and max values need to be tracked. ggplot can handle the issue of plot extents internally, so I’ve been playing around with using ggplot to plot time-lapse data. This is also a bit of a learning experience in terms of using ggplot to write general purpose plotting functions.

To give you an idea of what the output of the function I’ve been working on looks like, here is a sample plot:

The function is available on github and can be loaded through my personal R libraries using devtools from the R command line:

library(‘devtools’); 
install_github(‘mbergins/BerginskiRMisc’);

After loading my library, the above plot was produced with:

data = list(A = matrix(1:10,nrow=10,ncol=10) + rnorm(100), 
B = matrix(1:10,nrow=10,ncol=10) + rnorm(100) + 5,
C = matrix(1:10,nrow=10,ncol=10) + rnorm(100,sd=5));
thisPlot = buildTimelapsePlotWithConfInt(data);
thisPlot

You can expect your version of the plot to look a bit different depending on how the rnorm calls end up, but overall similar. The primary function is buildTimelapsePlotWithConfInt and the full documentation is available after loading my library.

--

--