[R-SIG-Finance] XTS - plot 8 years by month

James j at jtoll.com
Wed Jul 16 00:29:23 CEST 2008


On Jul 15, 2008, at 4:24 PM, Gabor Grothendieck wrote:

> On Tue, Jul 15, 2008 at 6:09 PM, James <j at jtoll.com> wrote:
>>
>> Hi,
>>
>> I have an xts object with eight years of monthly calculations, so  
>> a total of
>> 96 pieces of data.  What I would like to do is to plot 8 lines,  
>> one for each
>> year, with each months data aligned along the x axis.  So the x  
>> axis would
>> be each month, from Jan to Dec.  I tried using monthplot but it  
>> creates 12
>> lines for each of the months, not what I want.
>>
>> I know I can pull each years data by z['2000'].
>>> z['2000']
>>
>> 2000-01-21 0.2694149
>> 2000-02-18 0.2404871
>> 2000-03-17 0.2756291
>> 2000-04-21 0.2959471
>> 2000-05-19 0.2736563
>> 2000-06-16 0.2056082
>> 2000-07-21 0.1621791
>> 2000-08-18 0.1382985
>> 2000-09-15 0.1333139
>> 2000-10-20 0.2556851
>> 2000-11-17 0.2216605
>> 2000-12-15 0.2704414
>>
>> Does anyone know of an easy way to do this or do I have to create  
>> a new
>> data.frame with months by years?  Thanks.
>>
>
> Try this:
>
> # sample data
> z <- zooreg(1:96, start = as.Date("2000-01-01"))
>
> matplot(matrix(coredata(z), 12), type = "o", xaxt = "n", pch = paste 
> (0:7))
> axis(1, 1:12, month.abb)

Thanks Gabor,

That does exactly what I wanted.

James



More information about the R-SIG-Finance mailing list