# [R] plot time series

jessica.gervais at tudor.lu jessica.gervais at tudor.lu
Tue May 8 17:41:38 CEST 2007

```Dear All,

I sended my first mail as HTML by accident.
It has probably been stripped off... (see first mail below)
During that time, I was actually able to find a solution to my problem : I
wanted to plot times on a graph representing precipitation=f(time)

here is an example:

time<-c("2004-10-18 17:20:00","2004-10-18 17:50:00" ,"2004-10-18
18:40:00","2004-10-18 19:50:00","2004-10-18 20:00:00" ,"2004-10-18
20:10:00","2004-10-18 21:20:00" ,"2004-10-19 22:00:00" ,"2004-10-20
23:40:00")

precipitation<-c(0.1,0.5,0.0,0.8,1,2,5,9,1)

tt<-strptime(time,"%Y-%m-%d %H:%M:%S")
plot(tt,precipitation,xlab="time", xaxt="n")
r<-as.POSIXct(round(range(tt),"hours"))
axis.POSIXct(1,tt,at=seq(r[1],r[2],by="hour"),format="%Y-%m-%d %H:%M")

If you have better solution, I would be happy to know them,

Jessica

-----Jessica Gervais/CRTE/TUDOR wrote: -----

To: R-help at stat.math.ethz.ch
From: Jessica Gervais/CRTE/TUDOR
Date: 05/08/2007 03:37PM
Subject: plot time series

Dear all,

I have a question concerning plotting time measurements.

I have a time serie which record precipitation at different time steps for
different meteo sations.
Data are stored into a table :
first column is time (time steps between 2 measurement are variables)
secondcolumn is the measurement
I would like to plot precipitation=f(time) and write time in axis. I can
not use the plot.ts function as time steps between 2 measurements are
variables. I don't want to do a plot.ts as time steps are variable and also
as I
would like the different times to be written on the x-axis.I also would
like space
between each time step on the x-axis to be representativ of the real
amount of time.

Here is a example

time<-c("2004-10-18 17:20:00","2004-10-18 17:50:00" ,"2004-10-18
18:40:00","2004-10-18 19:50:00","2004-10-18 20:00:00" ,"2004-10-18
20:10:00","2004-10-18 21:20:00" ,"2004-10-18 22:00:00" ,"2004-10-18
23:40:00")

(is it automatically recognized as a time format?)

precipitation<-c(0.1,0.5,0.0,0.8,1,2,5,0.2,3)

plot(time,precipitation)
Error in plot.window(xlim, ylim, log, asp, ...) :
need finite 'xlim' values
1: NAs introduced by coercion
2: no non-missing arguments to min; returning Inf
3: no non-missing arguments to max; returning -Inf

Do anyone knows how to plot this kind os time dependant datas ?