Dear R users,
My immediate problem is that I do not seem to understand how to use the function
scale_x_datetime function in ggplot. My deeper problem is that I don?t
understand the use of the POSIXct class.
?
My data looks like like the following :
T????????? val
2009-11-04 23:59:57?? 972.357117????
2009-11-05 00:02:21?? 969.389221????
2009-11-05 00:04:45?? 868.817749????
2009-11-05 00:07:09?? 805.593079????
2009-11-05 00:09:33?? 928.946106????
2009-11-05 00:11:57?? 1004.880249??
2009-11-05 00:14:21?? 969.154846????
2009-11-05 00:16:45?? 989.090942????
2009-11-05 00:19:09?? 1009.907837??
2009-11-05 00:21:33?? 1058.458374??
2009-11-05 00:23:57?? 1179.298096??
??????
??????.
2009-11-06 23:57:23?? 650.345631
?
?
I attempted to code with the following :
?
df<-read.table(file=file1,header=TRUE,sep="\t",colClasses=c("character","numeric"))
# Could not directly read in the time with the POSIXct class instead of as
character
t1<-as.POSIXct(df$T)
# interested in a specific time frame
# first attempted without the CET in the limits
lim2<- c("2009-11-05 12:00:00 CET","2009-11-06 13:00:00
CET")
library(ggplot)
ggplot(data=df,aes(x=T,y=val))+geom_line()+scale_x_datetime(limits=lim2,format="%H")
?
I get the following error message :
#####
Error in if (length(range) == 1 || diff(range) == 0) { :
? missing value where TRUE/FALSE needed
In addition: Warning message:
In get("transform", env = trans, inherits = TRUE)(trans, ...) :
? NAs introduced by coercion
######
I next tried to get a subset of the dataframe with the following :
?
df2<-df [df$T>"2009-11-05 11:57:33 CET" &
df$T<"2009-11-06 12:59:57 CET",]> head(df2)
[1] Tid1 Rok
<0 rows> (or 0-length row.names)
?
I don?t seem to understand how I should work with the POSIXct class. And, this
is just the first step in my analysis (with many more steps pending)..
I will appreciate any and all the help that I can get.
Thanking you,
Ravi