Hello, I'm reading Time Series Analysis and its Applilcations with R Examples and I have a question... I notice that in the book there are timeseries plots but without the x-axis being labeled with dates. They are just numbers 1,...50,...100, etc. How do I get the date to show up on the x-axis? Here is my dateframe:> head(myData, 5)1 2008-01-30 08:30 7.00 2 2008-01-30 08:32 9.25 3 2008-01-30 08:34 5.50 4 2008-01-30 08:36 5.00 5 2008-01-30 08:38 -26.25 (Also, I have searched using Rseek.org and not found anything to help me. Any searching advice would be greatly appreciated.) -- View this message in context: http://www.nabble.com/datetime-on-x-axis-of-plot-tp15745910p15745910.html Sent from the R help mailing list archive at Nabble.com.
see the zoo package. It has all the plotting for timeseries. It has a nice Vignette too. Also have a look at timeseries functions in Rmetrics. (Rmetrics.org). Good luck. AA. ----- Original Message ----- From: "joshv" <josh.verdone at yahoo.com> To: <r-help at r-project.org> Sent: Thursday, February 28, 2008 4:04 PM Subject: [R] datetime on x-axis of plot> > Hello, I'm reading Time Series Analysis and its Applilcations with R > Examples > and I have a question... > > I notice that in the book there are timeseries plots but without the > x-axis > being labeled with dates. They are just numbers 1,...50,...100, etc. How > do I get the date to show up on the x-axis? > > Here is my dateframe: > >> head(myData, 5) > > 1 2008-01-30 08:30 7.00 > 2 2008-01-30 08:32 9.25 > 3 2008-01-30 08:34 5.50 > 4 2008-01-30 08:36 5.00 > 5 2008-01-30 08:38 -26.25 > > (Also, I have searched using Rseek.org and not found anything to help me. > Any searching advice would be greatly appreciated.) > > -- > View this message in context: > http://www.nabble.com/datetime-on-x-axis-of-plot-tp15745910p15745910.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.
Is the date part of your data a POSIXct object? If so, plot( myData[,1], myData[,2] ) will label the x axis with dates. See the help pages for date-time class objects: ?POSIXt (POSIXt includes both POSIXct and POSIXlt; I tend to prefer POSIXct and find it the easier of the two to work with, overall) -Don At 1:04 PM -0800 2/28/08, joshv wrote:>Hello, I'm reading Time Series Analysis and its Applilcations with R Examples >and I have a question... > >I notice that in the book there are timeseries plots but without the x-axis >being labeled with dates. They are just numbers 1,...50,...100, etc. How >do I get the date to show up on the x-axis? > >Here is my dateframe: > >> head(myData, 5) > >1 2008-01-30 08:30 7.00 >2 2008-01-30 08:32 9.25 >3 2008-01-30 08:34 5.50 >4 2008-01-30 08:36 5.00 >5 2008-01-30 08:38 -26.25 > >(Also, I have searched using Rseek.org and not found anything to help me. >Any searching advice would be greatly appreciated.) > >-- >View this message in context: >http://www.nabble.com/datetime-on-x-axis-of-plot-tp15745910p15745910.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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062
> From: joshv> Hello, I'm reading Time Series Analysis and its Applilcations with R Examples > and I have a question... > > I notice that in the book there are timeseries plots but without the x-axis > being labeled with dates. They are just numbers 1,...50,...100, etc. How > do I get the date to show up on the x-axis? > > Here is my dateframe: > > > head(myData, 5) > > 1 2008-01-30 08:30 7.00 > 2 2008-01-30 08:32 9.25 > 3 2008-01-30 08:34 5.50 > 4 2008-01-30 08:36 5.00 > 5 2008-01-30 08:38 -26.25Try this: # "foo.dat" is a two-column file with the data you gave earlier myData <- read.table("foo.dat", sep="\t", colClasses=c("POSIXct", "numeric")) # plot, but don't label the x-axis plot(myData, type="l", xaxt="n") # now, add labels to the x-axis axis.POSIXct(1, myData$V1, format="%m/%d %H:%M") Steve