\Header{interaction.plot}{Two-way Interaction Plot}
\keyword{hplot}{interaction.plot}
\begin{Description}\relax
Plots the mean (or other summary) of the response for two-way
combinations of factors, thereby illustrating possible interactions.\end{Description}
\begin{Usage}
\begin{verbatim}
interaction.plot(x.factor, trace.factor, response, fun = mean,
                 type = c("l", "p"), legend = TRUE,
                 trace.label = deparse(substitute(trace.factor)),
                 fixed = FALSE, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x.factor}] a factor whose levels will form the x axis.
\item[\code{trace.factor}] another factor whose levels will form the traces.
\item[\code{response}] a numeric variable giving the response
\item[\code{fun}] the function to compute the summary. Should return a single
real value.
\item[\code{type}] the type of plot: lines or points.
\item[\code{legend}] logical. Should a legend be included?
\item[\code{trace.label}] overall label for the legend.
\item[\code{fixed}] Should the legend be in the order of the levels of
\code{trace.factor} or in the order of the traces at their
right-hand ends?
\item[\code{...}] graphics parameters to be passed to the plotting routines.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
By default the levels of \code{x.factor} are plotted on the x axis in
their given order, with extra space left at the right for the legend
(if specified). If \code{x.factor} is an ordered factor and the levels
are numeric, these numeric values are used for the x axis.

The response and hence its summary can contain missing values. If so,
the missing values and the line segments joining them are omitted from
the plot (and this can be somewhat disconcerting).

The graphics parameters \code{xlab}, \code{ylab}, \code{ylim},
\code{lty}, \code{col} and \code{pch} are given suitable defaults
(and \code{xlim} and \code{xaxs} are set and cannot be overriden).
The defaults are to cycle through the line types, use the foreground
colour, and to use the symbols 1:9, 0, and the capital letters to plot
the traces.\end{Details}
\begin{Note}\relax
Some of the argument names and the precise behaviour are chosen for
S-compatibility.\end{Note}
\begin{Examples}
\begin{ExampleCode}
data(ToothGrowth)
attach(ToothGrowth)
interaction.plot(dose, supp, len, fixed=TRUE)
dose <- ordered(dose)
interaction.plot(dose, supp, len, fixed=TRUE)
detach()

data(OrchardSprays)
attach(OrchardSprays)
interaction.plot(treatment, rowpos, decrease)
interaction.plot(rowpos, treatment, decrease)
## order the rows by their mean effect
rowpos <- factor(rowpos, levels=sort.list(tapply(decrease, rowpos, mean)))
interaction.plot(rowpos, treatment, decrease)
detach()

data(esoph)
attach(esoph)
interaction.plot(agegp, alcgp, ncases/ncontrols)
interaction.plot(agegp, tobgp, ncases/ncontrols, trace.label="tobacco",
                 fixed=TRUE)
detach()
\end{ExampleCode}
\end{Examples}

