Dear R users, I have the following script to create bins of specified time intervals bin_end=60/bin_size bin_size=bin_size*100 h=seq(070000,180000,by=10000) breaks=c() for (i in h) { for (j in 0:(bin_end-1)) { value=i+(bin_size)*j breaks=append(breaks,value) } } I would like to plot then using the time as x-axis. I tried the following prova=zoo(myseries,times(breaks)) but of course I got the plot with the time as 80000, 90000, 100000 and so on. I would like only 08:00, 09:00 and so on (maybe also the half hours). How to do it? Thanks for your help, Marco -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002285.html Sent from the R help mailing list archive at Nabble.com.
On Oct 19, 2010, at 11:25 AM, Manta wrote:> > Dear R users, I have the following script to create bins of > specified time > intervals > > > bin_end=60/bin_size > bin_size=bin_size*100 > h=seq(070000,180000,by=10000) > breaks=c() > for (i in h) > { > for (j in 0:(bin_end-1)) > { > value=i+(bin_size)*j > breaks=append(breaks,value) > } > } > > > I would like to plot then using the time as x-axis. I tried the > following > > prova=zoo(myseries,times(breaks)) > > but of course I got the plot with the time as 80000, 90000, 100000 > and so > on. I would like only 08:00, 09:00 and so on (maybe also the half > hours). > How to do it?You seen to be under the mistaken impression that the internal representation of DateTime classes of 08:00 would be 80000. Since the internal representation of time is in seconds, the even number hours would be at integer multiples of 60*60. In addition the conversion of numeric to string in this situation may present some need to check for missing leading "0"'s. You ether need to describe the data situation more completely or adjust your expectations (or both). ?as.POSIXct ?strptime -- David.> > Thanks for your help, > Marco > > -- > View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002285.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
On Mon, Oct 25, 2010 at 4:12 PM, Manta <mantino84 at libero.it> wrote:> > I apologize for not being very precise. I meant the tick marks on the x-axis. > > As for the code, the situation is just the one describe above, just that I > would like to be able to specify the tick marks (say every 3 or 6 months).Using z and zjj from before: plot(z, xaxt = "n") axis(1, as.Date(time(zjj)), time(zjj)) or fancier: plot(z, xaxt = "n") jan <- as.numeric(format(time(zjj), "%m")) == 1 tt <- time(zjj) axis(1, as.Date(tt)[jan], format(tt[jan], "%Y")) axis(1, as.Date(tt)[!jan], format(tt, "%b")[!jan], tcl = -0.2) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Wonderful! Thanks a lot for your help, super appreciated! -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3012793.html Sent from the R help mailing list archive at Nabble.com.
On Wed, Oct 27, 2010 at 8:04 AM, Manta <mantino84 at libero.it> wrote:> > Here it is: > > dput(temp_plot) > structure(c(48608, 46686, 55216, 59268, 50967, 55067, 57783, > 60021, 61480, 63853, 58267, 72442, 63926, 49102, 74320, 63433, > 66256, 68483, 67736, 60507, 60888, 78008, 64326, 65665, 57288,...> ? ?1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names > c("sec", > "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst" > ), class = c("POSIXt", "POSIXlt")), class = "zoo")"POSIXlt" is not supported. You could use "POSIXct" but since this series is based on dates you really should be using "Date" class. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com