Perhaps inconsistent behavior in qplot ()?

I am trying to use qplot () to build a simple time series, as can be done with plot (). The variable x is equal to asPOSIXlt, and y is just some continuous measurement. Here is the code with brief comments. Any help regarding why these data.frames behave differently is greatly appreciated. As you can see below, I can solve the problem, but I'm curious why this is not working as I expected.

A few details:
platform: OS X 10.6.4
R: R 2.11.0

Disclaimer: I understand that I could delve into the source code and figure it out myself. I never used SO and thought this might be a good topic for this forum.

Disclaimer (2): I'm new to ggplot2

library(ggplot2) ws.dat <- read.csv("~/path/to/filename.csv",header=F) names(ws.dat) <- c("s","t","w") ws.dat$new.t <- as.POSIXlt(ws.dat$t) ws.dat[1:5,] ## stw new.t ## 1 29522 2005-07-02 00:00:00 5.00 2005-07-02 00:00:00 ## 2 29522 2005-07-02 00:10:00 5.29 2005-07-02 00:10:00 ## 3 29522 2005-07-02 00:20:00 5.48 2005-07-02 00:20:00 ## 4 29522 2005-07-02 00:30:00 5.54 2005-07-02 00:30:00 ## 5 29522 2005-07-02 00:40:00 5.49 2005-07-02 00:40:00 ## the following works plot(as.POSIXlt(ws.dat$t), ws.dat$w) ## doesn't work qplot(as.POSIXlt(t), w, data = ws.dat) ## Error in if (length(range) == 1 || diff(range) == 0) { : ## missing value where TRUE/FALSE needed ## doesn't work ws.dat$new.t <- as.POSIXlt(ws.dat$t) qplot(new.t, w, data = ws.dat) ## Same error as above ## Note - I could find a more elegant way of doing this; I'm just trying ## to reproduce as fast as possible. new.df <- data.frame(ws.dat$new.t, ws.dat$w) new.df[1:5,] ## ws.dat.new.t ws.dat.w ## 1 2005-07-02 00:00:00 5.00 ## 2 2005-07-02 00:10:00 5.29 ## 3 2005-07-02 00:20:00 5.48 ## 4 2005-07-02 00:30:00 5.54 ## 5 2005-07-02 00:40:00 5.49 ## 'works as *I* would expect'; this is != 'works *as* expected' qplot(ws.dat.new.t, ws.dat.w, data = new.df) 
+2
source share
2 answers

Use POSIXct - POSIXlt not suitable for inclusion in data frames. When you use data.frame to create a variable, it is automatically bound to POSIXct .

+2
source

When in doubt, look at the class of transferred objects! Thanks Hadley.

 class(new.df$ws.dat.new.t) ## [1] "POSIXt" "POSIXct" <--- ct!!!! class(as.POSIXlt(ws.dat$tt)) ## [1] "POSIXt" "POSIXlt" <--- lt!!!! 
+1
source

All Articles