[R] plot time series / dates (basic)
bogdan romocea
br44114 at yahoo.com
Mon Nov 1 22:30:30 CET 2004
Dear R users,
I'm having a hard time with some very simple things. I have a time
series where the dates are in the format 7-Oct-04. I imported the
file with read.csv so the date column is a factor. The series is
rather long and I want to plot it piece by piece. The function below
works fine, except that the labels for date are meaningless (ie
9.47e+08 or 1098000000 - apparently the number of seconds since
whatever). I don't want to convert the data frame to a ts object
because there are missing days and I don't want any interpolation.
1. How do I replace the date labels with something like 'Mar04',
instead of 9.47e+08 / 1098000000?
2. In the PDF file, the space between the two graphs printed pair by
pair is fairly large. Can I remove/reduce the area that seems
reserved for Title and X label so that, on a page, the space between
the graph at the top and the one at the bottom is minimized?
3. Given the function below, I haven't discovered a way to have
"vara" appear as the Title or Y label in graphs.
main=as.character(vara) lists all the values of vara (which is a
column from the data frame d). So, how can I use the name of a vector
as title or label in a plot?
Thank you,
b.
d <- ('data.csv', header = T, sep = ",", quote="", dec=".",
fill = T, skip=0)
attach(d)
#function to plot a long time series piece by piece
pl <- function(vara, varb, points)
{
date <- as.POSIXct(strptime(as.character(Date), "%d-%b-%y"), tz =
"GMT")
pr1 <- vector(mode="numeric")
pr2 <- vector(mode="numeric")
dat <- vector()
for (j in 1:(round(length(Vol)/points)+1)) #number of plots
{
for (i in ((j-1)*points+1):(j*points))
{
pr1[i-points*(j-1)] <- vara[i]
pr2[i-points*(j-1)] <- varb[i]
dat[i-points*(j-1)] <- date[i]
}
par(mfrow=c(2,1))
plot(dat, pr1, type="b")
plot(dat, pr2, type="b")
}
}
pdf("Rplots.pdf")
pl(Vol, atr, 50)
dev.off()
__________________________________
More information about the R-help
mailing list