[R] Questions related to plotting boxplots of time series data

Stephan Kolassa Stephan.Kolassa at gmx.de
Wed Apr 16 15:49:10 CEST 2008


Hi Thomas,

> I have looked through several R books and searched the web to find 
> answers to my questions with no results. I have an ensemble of time 
> series data (what are essentially Monte Carlo simulations) which I would 
> like to summarize as a time series of boxplots, by date/time at 6-hr 
> intervals. I don't know how to do this and I am not sure how I should 
> structure the data to get what I want. Another related question: while 
> doing this, can I have some of the time series shorter than others?

Once you have a (say) matrix containing the data, you can build a time 
series of boxplots by feeding a formula to boxplot():

times <- seq(1:20)
values <- matrix(rnorm(20*100,0,1),nrow=20,ncol=100)
boxplot(values~times)

Of course, you would need to align the time series values and take the 
six-hour-slices first. And then add prettyprinted labels.

> Ideally I would prefer to depict 99%, 95%, 75%, 50%, etc. confidence 
> intervals to show the distribution of the data. Is this possible? How 
> can I do it?

boxplot() by default shows 25%, 50% and 75% quantiles. The whiskers and 
circles are calculated through the interquartile range, see
http://en.wikipedia.org/wiki/Boxplot
Unfortunately, I can't seem to find this info in the help file for 
boxplot(). Thus, you would need to roll your own graphical 
representations after extracting quantiles via

apply(values,2,quantile,probs=c(.99,.95,.75,.5))

or some such. If you do roll your own, just please don't do 
"nonstandard" boxplots without telling the reader that your "whiskers" 
mean something different than in the ordinary boxplot...

Hope that helped
Stephan



More information about the R-help mailing list