3

I am making a plot in r with two series, which are essentially time series. Each series is an aggregate of multiple other series, so that each point in the time series has a mean and a variance. I would like both aggregate series on one plot, and I would like to show error bars at each point.The error bars would represent variance.

Here is a sample of the plot I'd like to add error bars to:

## random generation of series 1 components:
series1a<-rnorm(50,50,25)
series1b<-rnorm(50,49,26)
series1c<-rnorm(50,58,24)

## aggregate components into series 1:
series1.df<-t(data.frame(series1a,series1b,series1c))
series1<-colMeans(series1.df)

## random generation of series 2 components:
series2a<-rnorm(50,45,20)
series2b<-rnorm(50,44,21)
series2c<-rnorm(50,46,19)

## aggregate components into series 1:
series2.df<-t(data.frame(series2a,series2b,series2c))
series2<-colMeans(series2.df)

## plot:
plot(series1,type="o",col="blue",pch=0)
lines(series2,type="o",lty="dashed",col="red",pch=1)

Here is a picture of the plot that I would like to add error bars to: plot of two aggregate time series

Is there a simple way to add the error bars?

I'd like to avoid ggplot2 or other packages if possible.

Thanks.

Aarow
  • 131
  • 4
  • Thanks for the link. I had seen that duplicate, but I had trouble replicating it. I will try it again. – Aarow Nov 27 '17 at 15:38

0 Answers0