[R-SIG-Finance] How to add grid to plot.zoo easily

Wind windspeedo at qq.com
Sun Jan 11 15:51:51 CET 2009


quantmod and zoo are two packages I used most frequently. 
It's time for me to study zoo from ABC via these three pdf, I think.
Thanks Gabor.  
 
------------------ Original ------------------
From:  "Gabor Grothendieck"<ggrothendieck at gmail.com>;
Date:  Sun, Jan 11, 2009 10:43 PM
To:  "Wind"<windspeedo at qq.com>; 
Cc:  "r-sig-finance"<r-sig-finance at stat.math.ethz.ch>; 
Subject:  Re: [R-SIG-Finance] How to add grid to plot.zoo easily

 
On Sun, Jan 11, 2009 at 9:28 AM, Wind <windspeedo at qq.com> wrote:
> Sorry for suppling codes not reproducible.
> I think you have taught me enough on this issue:
> 1.  it is the fact that grid in R does not automatically align with Date and that is independent of zoo.
> 2.  there is vignette("zoo-faq"), besides vignette("zoo").

There are actually three zoo vignettes in total.  library(help = zoo)
lists them at the bottom.

> 3.  FAQ #8 is very useful for me.
> Thanks Gabor.
>
> Winds
>
>
> ------------------ Original ------------------
> From:  "Gabor Grothendieck"<ggrothendieck at gmail.com>;
> Date:  Sun, Jan 11, 2009 10:20 PM
> To:  "Wind"<windspeedo at qq.com>;
> Cc:  "r-sig-finance"<r-sig-finance at stat.math.ethz.ch>;
> Subject:  Re: [R-SIG-Finance] How to add grid to plot.zoo easily
>
>
> That's not reproducible:
>
>> require(RODBC)
> Loading required package: RODBC
>> require(zoo)
>> stock1<-getSymbol.RE("SH600036")
> Error: could not find function "getSymbol.RE"
>
> however, I suspect you are referring to the fact that
> grid in R does not automatically align with Date and
> that is independent of zoo.  The following misaligned
> plot does not use zoo:
>
> plot(Sys.Date() + 1:100, 1:100, pch = 20)
> grid()
>
> Tested in R version 2.8.1 Patched (2008-12-26 r47350)
>
> Its not clear here whether or not you are really
> using zoo but if you are then see the first example
> in the answer to zoo FAQ #8 "How are axes
> added to a plot created using plot.zoo?" and follow
> that code by the following line which does align the grid
> properly:
>
> abline(v = m, col = grey(0.8), lty = 2)
>
> The zoo FAQ is available via: vignette("zoo-faq")
>
>
> On Sun, Jan 11, 2009 at 6:17 AM, Wind <windspeedo at qq.com> wrote:
>> The grid() could add grids to plot easily.   But the vertical grids are not at the positions of  major ticks if we plot the time series.
>> I am satisfied with the major ticks generated by plot.zoo function.    Could we just add grids to plot.zoo according to the major ticks genereated by plot.zoo?
>>
>> The following codes work well except that the vertical grids not at the position of major ticks of x axis.
>>
>>>require(RODBC)
>>>require(zoo)
>>>stock1<-getSymbol.RE("SH600036")
>>>>head(stock1)
>>               Open     High      Low    Close Volume
>> 2002-04-09 4.288226 4.439191 4.288226 4.349428 101491
>> 2002-04-10 4.349428 4.365749 4.239264 4.324947  16651
>> 2002-04-11 4.324947 4.357588 4.280066 4.292306   5583
>> 2002-04-12 4.284146 4.341268 4.275985 4.312707   5208
>> 2002-04-15 4.312707 4.324947 4.222944 4.239264   4541
>> 2002-04-16 4.222944 4.239264 4.137261 4.145421   6107
>>> plot(stock1$Close)
>>> grid()
>>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>
>



More information about the R-SIG-Finance mailing list