| 27442 |
ripley |
1 |
\name{interaction.plot}
|
|
|
2 |
\alias{interaction.plot}
|
|
|
3 |
\title{Two-way Interaction Plot}
|
|
|
4 |
\description{
|
|
|
5 |
Plots the mean (or other summary) of the response for two-way
|
|
|
6 |
combinations of factors, thereby illustrating possible interactions.
|
|
|
7 |
}
|
|
|
8 |
\usage{
|
|
|
9 |
interaction.plot(x.factor, trace.factor, response, fun = mean,
|
|
|
10 |
type = c("l", "p"), legend = TRUE,
|
|
|
11 |
trace.label=deparse(substitute(trace.factor)), fixed=FALSE,
|
|
|
12 |
xlab = deparse(substitute(x.factor)), ylab = ylabel,
|
|
|
13 |
ylim = range(cells, na.rm=TRUE),
|
|
|
14 |
lty = nc:1, col = 1, pch = c(1:9, 0, letters),
|
|
|
15 |
xpd = NULL, leg.bg = par("bg"), leg.bty = "n",
|
|
|
16 |
xtick = FALSE, xaxt = par("xaxt"), axes = TRUE, \dots)
|
|
|
17 |
}
|
|
|
18 |
\arguments{
|
|
|
19 |
\item{x.factor}{a factor whose levels will form the x axis.}
|
|
|
20 |
\item{trace.factor}{another factor whose levels will form the traces.}
|
|
|
21 |
\item{response}{a numeric variable giving the response}
|
|
|
22 |
\item{fun}{the function to compute the summary. Should return a single
|
|
|
23 |
real value.}
|
|
|
24 |
\item{type}{the type of plot: lines or points.}
|
|
|
25 |
\item{legend}{logical. Should a legend be included?}
|
|
|
26 |
\item{trace.label}{overall label for the legend.}
|
|
|
27 |
\item{fixed}{logical. Should the legend be in the order of the levels
|
|
|
28 |
of \code{trace.factor} or in the order of the traces at their right-hand ends?}
|
|
|
29 |
\item{xlab,ylab}{the x and y label of the plot each with a sensible default.}
|
|
|
30 |
\item{ylim}{numeric of length 2 giving the y limits for the plot.}
|
|
|
31 |
\item{lty}{line type for the lines drawn, with sensible default.}
|
|
|
32 |
\item{col}{the color to be used for plotting.}
|
|
|
33 |
\item{pch}{a vector of plotting symbols or characters, with sensible
|
|
|
34 |
default.}
|
|
|
35 |
\item{xpd}{determines clipping behaviour for the \code{\link{legend}}
|
|
|
36 |
used, see \code{\link{par}(xpd)}. Per default, the legend is
|
|
|
37 |
\emph{not} clipped at the figure border.}
|
|
|
38 |
\item{leg.bg, leg.bty}{arguments passed to \code{\link{legend}()}.}
|
|
|
39 |
\item{xtick}{logical. Should tick marks be used on the x axis?}
|
|
|
40 |
\item{xaxt, axes, \dots}{graphics parameters to be passed to the plotting routines.}
|
|
|
41 |
}
|
|
|
42 |
\details{
|
|
|
43 |
By default the levels of \code{x.factor} are plotted on the x axis in
|
|
|
44 |
their given order, with extra space left at the right for the legend
|
|
|
45 |
(if specified). If \code{x.factor} is an ordered factor and the levels
|
|
|
46 |
are numeric, these numeric values are used for the x axis.
|
|
|
47 |
|
|
|
48 |
The response and hence its summary can contain missing values. If so,
|
|
|
49 |
the missing values and the line segments joining them are omitted from
|
|
|
50 |
the plot (and this can be somewhat disconcerting).
|
|
|
51 |
|
|
|
52 |
The graphics parameters \code{xlab}, \code{ylab}, \code{ylim},
|
|
|
53 |
\code{lty}, \code{col} and \code{pch} are given suitable defaults
|
|
|
54 |
(and \code{xlim} and \code{xaxs} are set and cannot be overriden).
|
|
|
55 |
The defaults are to cycle through the line types, use the foreground
|
|
|
56 |
colour, and to use the symbols 1:9, 0, and the capital letters to plot
|
|
|
57 |
the traces.
|
|
|
58 |
}
|
|
|
59 |
\note{
|
|
|
60 |
Some of the argument names and the precise behaviour are chosen for
|
|
|
61 |
S-compatibility.
|
|
|
62 |
}
|
|
|
63 |
\references{
|
|
|
64 |
Chambers, J. M., Freeny, A and Heiberger, R. M. (1992)
|
|
|
65 |
\emph{Analysis of variance; designed experiments.}
|
|
|
66 |
Chapter 5 of \emph{Statistical Models in S}
|
|
|
67 |
eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
\examples{
|
|
|
71 |
data(ToothGrowth)
|
|
|
72 |
attach(ToothGrowth)
|
|
|
73 |
interaction.plot(dose, supp, len, fixed=TRUE)
|
|
|
74 |
dose <- ordered(dose)
|
|
|
75 |
interaction.plot(dose, supp, len, fixed=TRUE, col = 2:3, leg.bty = "o")
|
|
|
76 |
detach()
|
|
|
77 |
|
|
|
78 |
data(OrchardSprays)
|
|
|
79 |
with(OrchardSprays, {
|
|
|
80 |
interaction.plot(treatment, rowpos, decrease)
|
|
|
81 |
interaction.plot(rowpos, treatment, decrease, cex.axis=0.8)
|
|
|
82 |
## order the rows by their mean effect
|
|
|
83 |
rowpos <- factor(rowpos, levels=sort.list(tapply(decrease, rowpos, mean)))
|
|
|
84 |
interaction.plot(rowpos, treatment, decrease, col = 2:9, lty = 1)
|
|
|
85 |
})
|
|
|
86 |
|
|
|
87 |
data(esoph)
|
|
|
88 |
with(esoph, {
|
|
|
89 |
interaction.plot(agegp, alcgp, ncases/ncontrols)
|
|
|
90 |
interaction.plot(agegp, tobgp, ncases/ncontrols, trace.label="tobacco",
|
|
|
91 |
fixed=TRUE, xaxt = "n")
|
|
|
92 |
})
|
|
|
93 |
}
|
|
|
94 |
\keyword{hplot}
|