| 42333 |
ripley |
1 |
% File src/library/stats/man/interaction.plot.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2007 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27442 |
ripley |
6 |
\name{interaction.plot}
|
| 56186 |
murdoch |
7 |
\alias{interaction.plot}
|
| 27442 |
ripley |
8 |
\title{Two-way Interaction Plot}
|
|
|
9 |
\description{
|
|
|
10 |
Plots the mean (or other summary) of the response for two-way
|
|
|
11 |
combinations of factors, thereby illustrating possible interactions.
|
|
|
12 |
}
|
|
|
13 |
\usage{
|
|
|
14 |
interaction.plot(x.factor, trace.factor, response, fun = mean,
|
| 57121 |
maechler |
15 |
type = c("l", "p", "b", "o", "c"), legend = TRUE,
|
| 30912 |
ripley |
16 |
trace.label = deparse(substitute(trace.factor)),
|
|
|
17 |
fixed = FALSE,
|
| 36816 |
ripley |
18 |
xlab = deparse(substitute(x.factor)),
|
|
|
19 |
ylab = ylabel,
|
| 61160 |
ripley |
20 |
ylim = range(cells, na.rm = TRUE),
|
| 27442 |
ripley |
21 |
lty = nc:1, col = 1, pch = c(1:9, 0, letters),
|
|
|
22 |
xpd = NULL, leg.bg = par("bg"), leg.bty = "n",
|
| 36816 |
ripley |
23 |
xtick = FALSE, xaxt = par("xaxt"), axes = TRUE,
|
|
|
24 |
\dots)
|
| 27442 |
ripley |
25 |
}
|
|
|
26 |
\arguments{
|
|
|
27 |
\item{x.factor}{a factor whose levels will form the x axis.}
|
|
|
28 |
\item{trace.factor}{another factor whose levels will form the traces.}
|
|
|
29 |
\item{response}{a numeric variable giving the response}
|
|
|
30 |
\item{fun}{the function to compute the summary. Should return a single
|
|
|
31 |
real value.}
|
| 57121 |
maechler |
32 |
\item{type}{the type of plot (see \code{\link{plot.default}}): lines
|
|
|
33 |
or points or both.}
|
| 27442 |
ripley |
34 |
\item{legend}{logical. Should a legend be included?}
|
|
|
35 |
\item{trace.label}{overall label for the legend.}
|
|
|
36 |
\item{fixed}{logical. Should the legend be in the order of the levels
|
|
|
37 |
of \code{trace.factor} or in the order of the traces at their right-hand ends?}
|
|
|
38 |
\item{xlab,ylab}{the x and y label of the plot each with a sensible default.}
|
|
|
39 |
\item{ylim}{numeric of length 2 giving the y limits for the plot.}
|
|
|
40 |
\item{lty}{line type for the lines drawn, with sensible default.}
|
|
|
41 |
\item{col}{the color to be used for plotting.}
|
|
|
42 |
\item{pch}{a vector of plotting symbols or characters, with sensible
|
|
|
43 |
default.}
|
|
|
44 |
\item{xpd}{determines clipping behaviour for the \code{\link{legend}}
|
|
|
45 |
used, see \code{\link{par}(xpd)}. Per default, the legend is
|
|
|
46 |
\emph{not} clipped at the figure border.}
|
|
|
47 |
\item{leg.bg, leg.bty}{arguments passed to \code{\link{legend}()}.}
|
|
|
48 |
\item{xtick}{logical. Should tick marks be used on the x axis?}
|
|
|
49 |
\item{xaxt, axes, \dots}{graphics parameters to be passed to the plotting routines.}
|
|
|
50 |
}
|
|
|
51 |
\details{
|
|
|
52 |
By default the levels of \code{x.factor} are plotted on the x axis in
|
|
|
53 |
their given order, with extra space left at the right for the legend
|
|
|
54 |
(if specified). If \code{x.factor} is an ordered factor and the levels
|
|
|
55 |
are numeric, these numeric values are used for the x axis.
|
|
|
56 |
|
|
|
57 |
The response and hence its summary can contain missing values. If so,
|
|
|
58 |
the missing values and the line segments joining them are omitted from
|
|
|
59 |
the plot (and this can be somewhat disconcerting).
|
|
|
60 |
|
|
|
61 |
The graphics parameters \code{xlab}, \code{ylab}, \code{ylim},
|
|
|
62 |
\code{lty}, \code{col} and \code{pch} are given suitable defaults
|
| 40281 |
ripley |
63 |
(and \code{xlim} and \code{xaxs} are set and cannot be overridden).
|
| 27442 |
ripley |
64 |
The defaults are to cycle through the line types, use the foreground
|
|
|
65 |
colour, and to use the symbols 1:9, 0, and the capital letters to plot
|
|
|
66 |
the traces.
|
|
|
67 |
}
|
|
|
68 |
\note{
|
|
|
69 |
Some of the argument names and the precise behaviour are chosen for
|
|
|
70 |
S-compatibility.
|
|
|
71 |
}
|
|
|
72 |
\references{
|
|
|
73 |
Chambers, J. M., Freeny, A and Heiberger, R. M. (1992)
|
|
|
74 |
\emph{Analysis of variance; designed experiments.}
|
|
|
75 |
Chapter 5 of \emph{Statistical Models in S}
|
| 47262 |
ripley |
76 |
eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
|
| 27442 |
ripley |
77 |
}
|
|
|
78 |
|
|
|
79 |
\examples{
|
| 41508 |
ripley |
80 |
require(graphics)
|
|
|
81 |
|
| 37838 |
ripley |
82 |
with(ToothGrowth, {
|
| 61160 |
ripley |
83 |
interaction.plot(dose, supp, len, fixed = TRUE)
|
| 27442 |
ripley |
84 |
dose <- ordered(dose)
|
| 61160 |
ripley |
85 |
interaction.plot(dose, supp, len, fixed = TRUE, col = 2:3, leg.bty = "o")
|
|
|
86 |
interaction.plot(dose, supp, len, fixed = TRUE, col = 2:3, type = "p")
|
| 37838 |
ripley |
87 |
})
|
| 27442 |
ripley |
88 |
|
|
|
89 |
with(OrchardSprays, {
|
|
|
90 |
interaction.plot(treatment, rowpos, decrease)
|
| 61160 |
ripley |
91 |
interaction.plot(rowpos, treatment, decrease, cex.axis = 0.8)
|
| 27442 |
ripley |
92 |
## order the rows by their mean effect
|
| 44243 |
ripley |
93 |
rowpos <- factor(rowpos,
|
|
|
94 |
levels = sort.list(tapply(decrease, rowpos, mean)))
|
| 27442 |
ripley |
95 |
interaction.plot(rowpos, treatment, decrease, col = 2:9, lty = 1)
|
|
|
96 |
})
|
|
|
97 |
|
|
|
98 |
with(esoph, {
|
| 30803 |
maechler |
99 |
interaction.plot(agegp, alcgp, ncases/ncontrols, main = "'esoph' Data")
|
| 61160 |
ripley |
100 |
interaction.plot(agegp, tobgp, ncases/ncontrols, trace.label = "tobacco",
|
|
|
101 |
fixed = TRUE, xaxt = "n")
|
| 30555 |
ripley |
102 |
})
|
|
|
103 |
## deal with NAs:
|
|
|
104 |
esoph[66,] # second to last age group: 65-74
|
|
|
105 |
esophNA <- esoph; esophNA$ncases[66] <- NA
|
|
|
106 |
with(esophNA, {
|
| 61160 |
ripley |
107 |
interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5)
|
| 47616 |
ripley |
108 |
# doesn't show *last* group either
|
| 61160 |
ripley |
109 |
interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5, type = "b")
|
| 30552 |
maechler |
110 |
## alternative take non-NA's {"cheating"}
|
| 61160 |
ripley |
111 |
interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5,
|
|
|
112 |
fun = function(x) mean(x, na.rm = TRUE),
|
| 30803 |
maechler |
113 |
sub = "function(x) mean(x, na.rm=TRUE)")
|
| 27442 |
ripley |
114 |
})
|
| 30555 |
ripley |
115 |
rm(esophNA) # to clear up
|
| 27442 |
ripley |
116 |
}
|
|
|
117 |
\keyword{hplot}
|