[R] questions about plot.zoo

Gabor Grothendieck ggrothendieck at gmail.com
Thu Dec 27 05:40:41 CET 2007

On Dec 26, 2007 10:55 PM, tom soyer <tom.soyer at gmail.com> wrote:
> I have been having very good results using plot.zoo to chart time series
> (1) when I tried to use semi-log scale, via log="y", R issued a warning,
> although it looked like plot.zoo plotted in semi-log scale anyway:
> Warning message:
> In plot.xy(xy.coords(x, y), type = type, ...) :
>  "log" is not a graphical parameter
> Does anyone know if I should ignore the warning, or discard the semi-log
> looking graph instead?

1. plot.zoo is passing the log= argument to the panel and in this case
panel=lines.  You can (a) ignore the warning, (b) use suppressWarnings
or (c) use a custom panel which excludes log:

lines2 <- function(...) { L <- list(...); L$log <- NULL; do.call(lines, L) }
z <- zoo(1:100)
plot(z, log = "y", panel = lines2)

> (2) I noticed that plot.zoo automatically generates major tick marks for the
> user. But does anyone know how to customize the major tick marks on the
> y-axis, and adding minor tick marks between them? I tried both axis() and
> minor.tick in the Hmisc package, but could not make them work. It seems that
> axis() and minor.tick do not work well with dates.

2.  If you are using a single panel then try this:
plot(z, yaxt = "n")
axis(2, c(1, 10, 100))

> (3) I tried to add horizontal grid like this:
> x=axis(4)
> abline(h=x,col="light gray")
> It works... but unfortunately, the grid lines are all drawn on top, or in
> front, of the lines or bars of data on the chart. As a result, the grid
> lines cover up the lines of data when they cross each other. Does anyone
> know if it is possible to specify the order of lines on a chart, i.e.,
> something like the z-index, so that the grid lines are behind the data
> lines? If not, then what would be the proper way of adding gridlines so that
> thay are consistent with the major and minor tick marks?

Try using xyplot.zoo.  See:
for an example which specifically shows how to do it.

More information about the R-help mailing list