Skip to content

How to add grid to plot.zoo easily

3 messages · Wind, Gabor Grothendieck

#
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.
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
#
I know the method of plot(,tck=1).   But I don't like this method because the
color of the grids is in "black" except to change the foreground color via
par() which will change the colors of other items, I guess.
Wind2 wrote:

  
    
#
That's not reproducible:
Loading required package: RODBC
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: