\HeaderA{grid}{Add Grid to a Plot}{grid}
\keyword{aplot}{grid}
\begin{Description}\relax
\code{grid} adds an \code{nx} by \code{ny} rectangular grid to an
existing plot.
\end{Description}
\begin{Usage}
\begin{verbatim}
grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted",
     lwd = NULL, equilogs = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{nx,ny}] number of cells of the grid in x and y direction.  When
\code{NULL}, as per default, the grid aligns with the tick marks on
the corresponding \emph{default} axis (i.e., tickmarks as computed by
\code{\LinkA{axTicks}{axTicks}}).  When \code{\LinkA{NA}{NA}}, no grid lines are
drawn in the corresponding direction.
\item[\code{col}] character or (integer) numeric; color of the grid lines.
\item[\code{lty}] character or (integer) numeric; line type of the grid lines.
\item[\code{lwd}] non-negative numeric giving line width of the grid lines;
defaults to \code{par("lwd")}.
\item[\code{equilogs}] logical, only used when \emph{log} coordinates and
alignment with the axis tick marks are active.  Setting \code{equilogs =
      FALSE} in that case gives \emph{non equidistant} tick aligned
grid lines.
\end{ldescription}
\end{Arguments}
\begin{Note}\relax
If more fine tuning is required, use \code{\LinkA{abline}{abline}(h = ., v = .)}
directly.
\end{Note}
\begin{SeeAlso}\relax
\code{\LinkA{plot}{plot}}, \code{\LinkA{abline}{abline}}, \code{\LinkA{lines}{lines}},
\code{\LinkA{points}{points}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
plot(1:3)
grid(NA, 5, lwd = 2) # grid only in y-direction

## maybe change the desired number of tick marks:  par(lab=c(mx,my,7))
op <- par(mfcol = 1:2)
with(iris,
     {
     plot(Sepal.Length, Sepal.Width, col = as.integer(Species),
          xlim = c(4, 8), ylim = c(2, 4.5), panel.first = grid(),
          main = "with(iris,  plot(...., panel.first = grid(), ..) )")
     plot(Sepal.Length, Sepal.Width, col = as.integer(Species),
          panel.first = grid(3, lty=1,lwd=2),
          main = "... panel.first = grid(3, lty=1,lwd=2), ..")
     }
    )
par(op)

\end{ExampleCode}
\end{Examples}

