Monday, October 26, 2009

Time series plot in R

Loading a dataset

data <- read.csv(file=paste("<directory>","<filename>",sep=""),head=TRUE,sep=",", stringsAsFactors=FALSE, nrows=rows)


Plotting a time-series:

print("### Time series plotting")
windows(24, 10)
#pdf(file="plot.pdf", width=8, height=10)
par(mfcol=c(5, 3),mar=c(3, 4, 1, 1),oma=c(2, 2, 4, 2)) #bottom, left, top, right
for(j in 1:ncol(data))
{
#Print dots
plot(<index_array>, data[,j], type='p', pch=".", cex=3, ylab="<ylabel>", col=<color_list>,xlab=NA,ylim=c(0,100))
#Draw line
plot(<index_array>, data[,j], type='l', ylab="<ylabel>", col=<some_color>, xlab=NA, ylim=c(0,100))
if (j==1)
{
title(main=paste("<title>", "<here>"))
}
}
#dev.off()

No comments: