[R] Plotting Time against Date for time series data?

About this list Date view Thread view Subject view Author view Attachment view

From: Slist (slist@oomvanlieshout.net)
Date: Mon 17 May 2004 - 23:13:29 EST


Message-id: <6.1.0.6.0.20040517131117.02526be0@localhost>

Dear all,

I have a data set containing GPS fixes of animal locations. To check that
the GPS's are working properly, I would like to plot the time of the fixes
(y-axis) against the date of the fixes (x-axis). If all works well, the
plot should show four regular fixes per day. The x-axis should be labelled
with month/year (i.e. 11/04) and the y-axis by hour from 00 to 24. I would
like to control the x-axis limits.

I have looked at several date and time related help pages, but get horribly
lost in all the terminology. The main challenge is to isolate date and time
from the date/time object for plotting (marked ???). Therefore, I would
like the following example code to work:

>
>
dates <- c("02/27/92", "02/27/92", "01/14/92", "01/14/92", "03/28/92",
"03/28/92") #
times <- c("23:03:20", "10:29:56", "01:03:30", "13:03:30", "18:21:03",
"06:56:26") #
x <- paste(dates, times) #
DateTime <- strptime(x, "%m/%d/%y %H:%M:%S") #

Date <- DateTime ??? #
Time <- DateTime ??? #
plot(x=Date, y=Time,
         xlab= "Date (month/year)", ylab= "Time (hours)", xaxt="n", yaxt="n",
         xlim=c(as.Date("01/01/92", format="%m/%d/%y"), as.Date("04/01/92",
format="%m/%d/%y")),
         ylim=c(0, 24)
         ) #
r <- as.POSIXct(round(range(Date), "days")) #
axis.POSIXct(1, at=seq(r[1], r[2], by="month"), format="%m/%y") #
r <- as.POSIXct(round(range(Time), "hours")) #
axis.POSIXct(2, at=seq(r[1], r[2], by="hour"), format="%H") #
>
>

Thanks for any suggestions,

Sander Oom.

--------------------------------------------------------------
Dr. Sander P. Oom
Animal, Plant and Environmental Sciences
University of the Witwatersrand
Private Bag 3
Wits 2050
South Africa

Tel (work) +27 (0)11 717 64 04
Tel (home) +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64

Email sander@oomvanlieshout.net
Web www.oomvanlieshout.net/sander

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:11 EST