I draw the results of 50 - 100 experiments. Each experiment leads to a time series. I can plot the spaghetti chart of all time series, but what I would like to have is a density map for the time series. (something similar to gray shading in the bottom panel in this illustration: http://www.ipcc.ch/graphics/ar4-wg1/jpg/fig-6-14.jpg )

I can sort this using 2d binning or binhex, but the result may be more beautiful (see example below).
Here is the code that reproduces the plume graph for the layout data (uses ggplot2 and reshape2).
# mock data: random walk plus a sinus curve. # two envelopes for added contrast. tt=10*sin(c(1:100)/(3*pi)) rr=apply(matrix(rnorm(5000),100,50),2,cumsum) +tt rr2=apply(matrix(rnorm(5000),100,50),2,cumsum)/1.5 +tt # stuff data into a dataframe and melt it. df=data.frame(c(1:100),cbind(rr,rr2) ) names(df)=c("step",paste("ser",c(1:100),sep="")) dfm=melt(df,id.vars = 1) # ensemble average ensemble_av=data.frame(step=df[,1],ensav=apply(df[,-1],1,mean)) ensemble_av$variable=as.factor("Mean") ggplot(dfm,aes(step,value,group=variable))+ stat_binhex(alpha=0.2) + geom_line(alpha=0.2) + geom_line(data=ensemble_av,aes(step,ensav,size=2))+ theme(legend.position="none")
Does anyone know a good way to get a shaded envelope with gradients. I also tried geom_ribbon, but this did not give any indication of density changes along the plume. binhex does this, but not with aesthetically pleasing results.
r ggplot2
Halldór Björnsson
source share