[R] Chron object in time series plot

Gabor Grothendieck ggrothendieck at gmail.com
Mon Oct 25 21:28:42 CEST 2010


On Mon, Oct 25, 2010 at 3:01 PM, Manta <mantino84 at libero.it> wrote:
>
> I would like to thank you all for the help given so far!
>
> I have the following object of the class 'zoo'
>
>> temp_mean_plot[31:35]
> 2008-02-13 2008-02-14 2008-02-15 2008-02-18 2008-02-19
>  14.86834   14.89609   14.89358   14.87610   14.87652
>
> The sample runs from Jan 2008 to July 2010. How can I specify to plot for
> example Jan08, Jul08, Jan09 etc?
>
> I've seen some example as in example(plot.zoo) but I cant get exactly how to
> replicate it for my purpose. Any help will be highly appreciated again.

Assuming that you are looking for a single plot that shows the last
point in each January and the last point in each July and no other
point then the following creates a test series, z, and aggregates it
down to a monthly series, picks off the January and July months and
plots:

library(zoo)

# test data
z <- zooreg(1:1000, start = as.Date("2000-01-01"))

zym <- aggregate(z, as.yearmon, function(x) tail(x, 1))
mon <- as.numeric(format(time(zym), "%m"))
zjj <- zym[mon %% 6 == 1, ]
plot(zjj, type = "o"); grid()

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list