Re: [R] Problem with plot() and POSIXt dates

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 05 Jan 2007 - 14:44:01 GMT

Sorry, there was a missing parenthesis after the first statement. Here is the code again:

x <- seq(from = as.POSIXct("2005-10-14"),

      to = as.POSIXct("2007-01-02"),
      by = "day")

y <- as.numeric(x)

plot(y ~ x, xaxt = "n")
at <- x[seq(1, length(x), length = 5)]
axis.POSIXct(1, at, at, "%y-%b-%d")

On 1/5/07, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> We can force the X axis into the format of our choice by
> suppressing it in the plot and explicitly calling
> axis.POSIXct with our choice of format
> (see ?axis.POSIXct):
>
> x <- seq(from = as.POSIXct("2005-10-14"),
> to = as.POSIXct("2007-01-02"),
> by = "day"
> y <- as.numeric(x)
>
> plot(y ~ x, xaxt = "n")
> at <- x[seq(1, length(x), length = 5)]
> axis.POSIXct(1, at, at, "%y-%b-%d")
>
> Actually your data appear to be dates rather than date times
> so I would use Date class rather than POSIXct. See the Help
> Desk article on dates and times in R News 4/1.
>
> [Try making your examples smaller and more self contained
> such as shown above.]
>
> On 1/5/07, COMTE Guillaume <g.comte@alliance-ir.net> wrote:
> > So maybe i will finaly succeed asking the right way,
> >
> >
> >
> > Hy all,
> >
> > I'm plotting graphs using plot() function, they are on X axes POSIX dates:
> >
> > "POSIXt" "oldClass" "POSIXct" "POSIXlt"
> >
> > I can't figure out why sometimes it prints the month and days and sometimes it prints the unix timestamps.
> >
> > Here is an example that reproduce my problem the data's to use with it can be downloaded from http://www.alliance-ir.net/r-project/demo.tar.gz <http://www.alliance-ir.net/r-project/demo.tar.gz> :
> >
> > limite_x<-structure(as.numeric(read.table("limite_x")), class=c("POSIXt","POSIXct"))
> >
> > limite_y<-as.numeric(read.table("limite_y"))
> >
> > test<-as.numeric(read.table("y_values"))
> >
> > abscisse_test<-structure(as.numeric(read.table("x_values")), class=c("POSIXt","POSIXct"))
> >
> > plot((test/10)~abscisse_test,type="s",col="lightgreen",xlab="",ylab="",ylim=limite_y,xlim=limite_x)
> >
> > length_test<-length(test)
> >
> > #if i cut the var "test" to be closer to xlim values, i know that xlim is at the end of "test" :
> >
> > test_short<-test[(length_test-10):length_test]
> >
> > abscisse_test_short<-abscisse_test[(length_test-10):length_test]
> >
> > plot((test_short/10)~abscisse_test_short,type="s",col="lightgreen",xlab="",ylab="",ylim=limite_y,xlim=limite_x)
> >
> > dev.off()
> >
> > > sessionInfo()
> >
> > R version 2.4.0 (2006-10-03)
> >
> > i386-pc-linux-gnu
> >
> >
> >
> > locale:
> >
> > LC_CTYPE=fr_FR@euro;LC_NUMERIC=C;LC_TIME=fr_FR@euro;LC_COLLATE=fr_FR@euro;LC_MONETARY=fr_FR@euro;LC_MESSAGES=fr_FR@euro;LC_PAPER=fr_FR@euro;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR@euro;LC_IDENTIFICATION=C
> >
> >
> >
> > attached base packages:
> >
> > [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets"
> >
> > [7] "base"
> >
> >
> >
> > COMTE Guillaume
> >
> > Ingénieur Projet
> >
> > Alliance Technologies
> >
> > Projet Philharmonie
> >
> > 24 rue Martre
> >
> > 92110 Clichy
> >
> > Tel : 01 40 87 48 06
> >
> > Fax : 01 40 87 48 14
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> >
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch 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.
> >
> >
> >
>



R-help@stat.math.ethz.ch 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. Received on Sat Jan 06 01:54:06 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 05 Jan 2007 - 15:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.