[R] Posix data in Lattice

Shawn Way sway at tanox.com
Fri Apr 25 18:13:18 CEST 2003


A variation of this did the trick.  I had to manually scale the number of
ticks, but it works out well.

Thank you..

-----Original Message-----
From: Renaud Lancelot [mailto:renaud.lancelot at cirad.fr] 
Sent: Friday, April 25, 2003 10:48 AM
To: Shawn Way
Subject: Re: [R] Posix data in Lattice


Shawn Way wrote:
> I have a number of plots that I'm trying to do using the lattice 
> package, unfortunately, they involve Posix values.
> 
> A small sample of the data is as follows:
> 
>                    Time   TC.1  <Snipped>
> 1   2003-04-24 13:29:15  26.61
> 2   2003-04-24 13:29:30  26.48
> 3   2003-04-24 13:30:00  26.53
> 4   2003-04-24 13:30:30  27.85
> <Snipped>
> 
> where
> 
> str(data)
> `data.frame':	415 obs. of  22 variables:
>  $ Time :`POSIXlt', format: chr  "2003-04-24 13:29:15" "2003-04-24 
> 13:29:30" "2003-04-24 13:30:00" "2003-04-24 13:30:30" ...
>  $ TC.1 : num   26.6  26.5  26.5  27.9 100.0 ...
> <Snipped>
> 
> What I'm trying to do is plot TC.1 vs Time (which I can do easily), 
> but I need the xaxis to represent the Time instead of a numeric such 
> as 105121000,etc.
> 
> I also need to rotate the times, but I think I have that figured 
> out...

format looks what you need (see below). Here is a start, but I am not 
very easy with as.POSIX**. In particular, I don't know how to convert 
from numeric to POSIX**.

x    <- as.POSIXlt(ISOdate(2002, 4, 25, 12) + seq(0, 3600 * 3, 1800))
y    <- rnorm(length(x$min))
nlab <- as.numeric(as.POSIXct(x))
clab <- format(x, format = "%H:%M")
foo <- data.frame(Y = y, X = nlab)
rm(x, y, nlab, clab)
x    <- as.POSIXlt(ISOdate(2002, 4, 25, 12) + seq(0, 3600 * 3, 1800))
y    <- rnorm(length(x$min))
nlab <- as.numeric(as.POSIXct(x))
clab <- format(x, format = "%H:%M")
foo <- data.frame(y = y, x = nlab)
rm(x, y)
library(lattice)
xyplot(y ~ x, data=foo, scales=list(x = list(at=nlab, labels=clab)))

Best,

Renaud



-- 
Dr Renaud Lancelot, vétérinaire
CIRAD, Département Elevage et Médecine Vétérinaire (CIRAD-Emvt) Programme
Productions Animales http://www.cirad.fr/fr/pg_recherche/page.php?id=14

ISRA-LNERV                      tel    +221 832 49 02
BP 2057 Dakar-Hann              fax    +221 821 18 79 (CIRAD)
Senegal                         e-mail renaud.lancelot at cirad.fr



More information about the R-help mailing list