I had to go the long way round with this so here's what I did (Using the 25% and 75% percentile):
##Create matrix
B = matrix (c(2,4,3,1,5,7,5,3,8,3,7,3),nrow=4,ncol=3)
##Create dataframe
B2<-as.data.frame(B)
colnames(B2)<- c("A","B","C")
##Create date sequence
##To compute quantile by row
D<-apply(B2,2,quantile)
##Select 1st and 3rd quartile (25% and 75%) and transpose to make them columns.
D2<-t(D[c(2,4),])
##Mean
CO<-apply(B2,2,mean)
DM<-as.data.frame(cbind(D2,CO))
##Create dates
Date<-as.character(as.yearmon (seq(as.Date("2000/1/1"), by = "month", length.out = 3)))
##Add to dataframe
DM$Date<-Date
colnames(DM)<-c("Q1","Q3","CO","Date")
##Plot using ggplot2
library(ggplot2)
ggplot(DM, aes(x=Date, y=CO,group=1,colour="CO")) +
geom_errorbar(aes(ymin=Q1, ymax=Q3), width=.1) +
geom_point(size=3) +
geom_line(aes())
Here's the result with the time series line connecting the mean for each month:
I won't mind an easier way of doing this if there are any ideas.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…