Hi, everyone I've been trying to make a scatter plot of POSIXct format data to see the difference between two start time. Like X: [1] "1995-05-26 19:00:00" "1995-05-27 01:00:00" "1995-05-27 07:00:00" [4] "1995-06-29 01:00:00" "1995-06-29 07:00:00" "1995-06-30 13:00:00" [7] "1995-06-30 19:00:00" "1995-07-01 01:00:00" "1995-07-01 07:00:00" ...... Y: [1] "1995-05-26 19:00:00" "1995-05-27 01:00:00" "1995-05-27 07:00:00" [4] "1995-06-29 01:00:00" "1995-06-29 07:00:00" "1995-06-30 13:00:00" [7] "1995-06-30 19:00:00" "1995-07-01 01:00:00" "1995-07-01 07:00:00" ....... But it seems plot(x,y) doesn't work, y have to be numeric format. Is there any special command for that or I should change the format of the data? Thanks Jingru Dai ---- School of Mathematical Sciences Rm 454, Building 28 Monash University, 3800 Victoria, Australia
When I try this:> x <- as.POSIXct(Sys.Date() + 0:9) > plot(x, x) > plot(x ~ x)The first one does give me dates on both axes but the second one gives numbers on the Y axis. Note that you can always not print the axis with plot and then do it yourself with axis or Axis. This works for me:> plot(x ~ x, yaxt = "n") > Axis(x, side = 2)> R.version.string # Windows Vista[1] "R version 2.6.1 Patched (2007-12-06 r43610)" On Jan 14, 2008 6:37 PM, Jingru Dai <jingru.dai at sci.monash.edu.au> wrote:> Hi, everyone > > I've been trying to make a scatter plot of POSIXct format data to see > the difference between two start time. > Like X: > [1] "1995-05-26 19:00:00" "1995-05-27 01:00:00" "1995-05-27 07:00:00" > [4] "1995-06-29 01:00:00" "1995-06-29 07:00:00" "1995-06-30 13:00:00" > [7] "1995-06-30 19:00:00" "1995-07-01 01:00:00" "1995-07-01 07:00:00" > ...... > Y: > [1] "1995-05-26 19:00:00" "1995-05-27 01:00:00" "1995-05-27 07:00:00" > [4] "1995-06-29 01:00:00" "1995-06-29 07:00:00" "1995-06-30 13:00:00" > [7] "1995-06-30 19:00:00" "1995-07-01 01:00:00" "1995-07-01 07:00:00" > ....... > > But it seems plot(x,y) doesn't work, y have to be numeric format. Is > there any special command for that or I should change the format of the > data? > Thanks > > Jingru Dai > ---- > School of Mathematical Sciences > Rm 454, Building 28 > Monash University, 3800 > Victoria, Australia > > ______________________________________________ > 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. >
On Tue, 15 Jan 2008, Jingru Dai wrote:> Hi, everyone > > I've been trying to make a scatter plot of POSIXct format data to see > the difference between two start time. > Like X: > [1] "1995-05-26 19:00:00" "1995-05-27 01:00:00" "1995-05-27 07:00:00" > [4] "1995-06-29 01:00:00" "1995-06-29 07:00:00" "1995-06-30 13:00:00" > [7] "1995-06-30 19:00:00" "1995-07-01 01:00:00" "1995-07-01 07:00:00" > ...... > Y: > [1] "1995-05-26 19:00:00" "1995-05-27 01:00:00" "1995-05-27 07:00:00" > [4] "1995-06-29 01:00:00" "1995-06-29 07:00:00" "1995-06-30 13:00:00" > [7] "1995-06-30 19:00:00" "1995-07-01 01:00:00" "1995-07-01 07:00:00" > ....... > > But it seems plot(x,y) doesn't work, y have to be numeric format. Is > there any special command for that or I should change the format of the > data?It's possible, but there is not a canned solution. You could look at the code of graphics:::plot.POSIXct and modify to treat x the same way as y. Or simply use plot(x,y, xaxt="n", yaxt="n") axis.POSIXct(1, x) axis.POSIXct(2, y)> Thanks > > Jingru Dai > ---- > School of Mathematical Sciences > Rm 454, Building 28 > Monash University, 3800 > Victoria, Australia-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595