Hello, Im reading Data out of a Database. #v+ rs <- dbGetQuery(con,"SELECT * ... ) attach(rs) #v- There ist a colum I convert into "Time". #v+> zeit<-strptime(datum,format="%Y-%m-%d %H:%M:%S"); > class(zeit)[1] "POSIXt" "POSIXlt" #v- 1. A plot(zeit,money) plots the Data. All i see on the x-achis are the Days. I would like to see the hours also. 2. length(zeit) gives mit the length of one entry. But zeit exists of 500 entries. How can i get the amount of entries zeit got? 3. Im used to draw whith lines() into an existing plot. But something like lines(zeit,food) wouldnt work. All this works quit well, when Im using unixtime. But seconds since 1970 are not that nice on the x-achis:-) Regards Erkan Yanar -- ?ber den grenzen mu? die freiheit wohl wolkenlos sein
You normally want to represent your times as POSIXct rather than POSIXlt so try xct <- as.POSIXct(xlt) or you may want to use chron. Read read more about this in R News 4/1 which has info on dates and times. Use the axis or Axis command to create custom axes. ?axis ?Axis You may also want to look at the zoo package which has numerous examples of working with and plotting time series including three vignettes. On Thu, Mar 27, 2008 at 9:59 AM, erkan yanar <erkan.yanar at linsenraum.de> wrote:> > Hello, > > Im reading Data out of a Database. > #v+ > rs <- dbGetQuery(con,"SELECT * ... ) > attach(rs) > #v- > > There ist a colum I convert into "Time". > > #v+ > > zeit<-strptime(datum,format="%Y-%m-%d %H:%M:%S"); > > class(zeit) > [1] "POSIXt" "POSIXlt" > #v- > > 1. > A plot(zeit,money) plots the Data. > All i see on the x-achis are the Days. > I would like to see the hours also. > > 2. > length(zeit) gives mit the length of one entry. > But zeit exists of 500 entries. > How can i get the amount of entries zeit got? > > 3. > Im used to draw whith lines() into an existing plot. > But something like lines(zeit,food) wouldnt work. > > All this works quit well, when Im using unixtime. But seconds since > 1970 are not that nice on the x-achis:-) > > > > Regards > Erkan Yanar > > > > -- > ?ber den grenzen mu? die freiheit wohl wolkenlos sein > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
As Gabor said, your zeit should be a POSIXct object, not a POSIXlt object. Then, for example: zeit <- Sys.time() + 1500000*runif(10) val <- rnorm(10) plot(zeit,val,xaxt='n') axis.POSIXct(1,zeit, format='%Y-%m-%d %H:%M') Or better (perhaps) yet: plot(zeit,val,xaxt='n') axis.POSIXct(1,zeit, format='%Y-%m-%d\n%H:%M', mgp=c(3,2,0)) However, depending on the overall time range, this example might make more sense: zeit <- Sys.time() + 15000*runif(10) plot(zeit,val,xaxt='n') axis.POSIXct(1,zeit, format='%Y-%m-%d\n%H:%M', mgp=c(3,2,0))> class(zeit)[1] "POSIXt" "POSIXct" -Don At 2:59 PM +0100 3/27/08, erkan yanar wrote:>Hello, > >Im reading Data out of a Database. >#v+ >rs <- dbGetQuery(con,"SELECT * ... ) >attach(rs) >#v- > >There ist a colum I convert into "Time". > >#v+ >> zeit<-strptime(datum,format="%Y-%m-%d %H:%M:%S"); >> class(zeit) >[1] "POSIXt" "POSIXlt" >#v- > >1. >A plot(zeit,money) plots the Data. >All i see on the x-achis are the Days. >I would like to see the hours also. > >2. >length(zeit) gives mit the length of one entry. >But zeit exists of 500 entries. >How can i get the amount of entries zeit got? > >3. >Im used to draw whith lines() into an existing plot. >But something like lines(zeit,food) wouldnt work. > >All this works quit well, when Im using unixtime. But seconds since >1970 are not that nice on the x-achis:-) > > > >Regards >Erkan Yanar > > > >-- >?ber den grenzen mu? die freiheit wohl wolkenlos sein > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062