[R] x-axis with month and year

Gabor Grothendieck ggrothendieck at gmail.com
Sat Aug 16 01:42:36 CEST 2008


Note that this works:

y <- rnorm(168)
z <- zooreg(y, start = as.yearmon(1993), freq = 12)
plot(z)

and this also works and does not require zoo but
won't automatically put ticks on the months:

tt <- ts(y, start = 1993, freq = 12)
plot(tt)

On Fri, Aug 15, 2008 at 7:13 PM, Schreiber, Stefan
<Stefan.Schreiber at ales.ualberta.ca> wrote:
> Thanks for steering me in the right direction!
>
> However, I did it slightly different:
>
> require(zoo)
> x <- yearmon(1993 + seq(0, 167)/12)
>
> plot(mydata$CMI~x)
>
>
> Thanks!
>
> Stefan
>
> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com]
> Sent: Friday, August 15, 2008 2:06 PM
> To: Schreiber, Stefan
> Cc: r-help at r-project.org
> Subject: Re: [R] x-axis with month and year
>
> Check out the zoo package:
>
> Lines <- "Date,CMI
> Jan-93,3.24
> Feb-93,-2.56
> Dec-06, 8.25"
>
> library(zoo)
> z <- read.zoo(textConnection(Lines),
>  FUN = as.yearmon, format = "%b-%y",
>  sep = ",", header = TRUE)
> plot(z)
>
>
> On Fri, Aug 15, 2008 at 1:12 PM, Schreiber, Stefan
> <Stefan.Schreiber at ales.ualberta.ca> wrote:
>> Hey list!
>>
>> I have a csv-file with two variables: (Date,CMI)
>>
>> Date,CMI
>> Jan-93,3.24
>> Feb-93,-2.56
>> .
>> .
>> .
>> Dec-06, 8.25
>>
>>
>> When I want to plot this dataset, R is sorting the date in
> alphabetical
>> order. Is there any way to tell R not to do it?
>>
>> I know it is probably an easy issue but I couldn't find a solution so
>> far. I have seen so many tips already but can't apply it on my own
>> dataset.
>>
>> Thank you very much!
>>
>> Stefan
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>



More information about the R-help mailing list