[R] Plotting hourly time-series data loaded from file using plot.ts

Keith kigiokli at gmail.com
Wed Jul 15 16:07:12 CEST 2009


Hello everyone,

I am just a tyro in R and would like your kindly help for some
problems which I've been struggling for a while but still in vain.

I have a time-series file (with some missing value ) which looks like

time[sec] , Factor1 , Factor2
00:00:00 01.01.2007 , 0.0000 , 0.176083
01:00:00 01.01.2007 , 0.0000 , 0.176417
[ ... ]
11:00:00 10.06.2007 , 0.0000 , 0.148250
12:00:00 10.06.2007 , NA , 0.147000
13:00:00 10.06.2007 , NA , 0.144417
[ ... ]

and I would like to do some basic time-series analyses using R. The
first idea is to plot these time-series events and the main problem
was the handling of the date/time format in the 1st column. I was
using the script below to deal with:

data <- read.table("file",header=TRUE,sep=",",colClasses=c("character","numeric","numeric"))
data$time.sec. <- as.POSIXct(data$time.sec.,format="%H:%M:%S %d.%m.%Y")
dataTs <- as.ts(data)
plot.ts(dataTs)

Then, the plot showed up with 3 subplots in one plot. The 1st is the
linear line with the x-axis being just the sequence of orders and
y-axis being wrong numbers which is completely wrong. The 2nd and the
3rd are correct but the x-axis is still wrong. Does anyone know how to
plot correct Factor1 and Factor2 with respect to the 1st column time
format? Or, probably should I use some other packages? Besides, how
can I plot these two time-series data (Factor1 and Factor2) in two
separate plots?

Best regards,
Keith




More information about the R-help mailing list