-1

I used the zoo package to create a monthly date sequence as follows:

x <- zooreg(1:144, start = as.yearmon("2003-1"), frequency = 12)

But now I do have the problem that when I create a plot (with base R), the date does not appear "right": The x-axis shows values from 1 to 144.

Let's say I create my plot like this:

library(zoo)
x <- zooreg(1:144, start = as.yearmon("2003-1"), frequency = 12)
y <- sample(1:1000, 144)
plot(x,y, type="n")
lines(x, y)

Best regards

Gilles Cosyn
  • 435
  • 2
  • 9
  • 17
  • possible duplicate of this [http://stackoverflow.com/questions/4843969/plotting-time-series-with-date-labels-on-x-axis](http://stackoverflow.com/questions/4843969/plotting-time-series-with-date-labels-on-x-axis) – NicE Mar 01 '15 at 18:32

1 Answers1

2

It's unclear what you are really trying to do. First, the lines() command without a prior plot() will not draw anything. Second, if the data you want to plot is 100:244 (or rather 101:244) then you should include that in the zoo object x (instead of the 1:144). Third, just using plot(x) (i.e., using zoo's plot method) draws the correct x-axis.

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • Your modification clarifies the first but not the second and third issues raised in my answer. The second point means that you can create a zoo series with the correct data by `x <- zooreg(sample(1:1000, 144), start = as.yearmon("2003-1"), frequency = 12)` and the third point means that you then just call `plot(x)`. – Achim Zeileis Mar 03 '15 at 18:55
  • Thanks. I guess that was what I was looking for. I did not (and still do not completely) understand the zoo package. What bothers me, is the standard plot(x). Isn't it still possible to customize the plot by using lines and (png) graphics devices? – Gilles Cosyn Mar 04 '15 at 09:50
  • Of course, there is also a `lines()` method for `zoo` objects. I suggest that you start out by reading the `zoo` and/or `zoo-quickref` vignettes provided in the package. As for the `png()` device, I don't see why this changes anything... – Achim Zeileis Mar 04 '15 at 11:46