the function to compute the summary. Should return a single
real value.
type
the type of plot (see plot.default): lines
or points or both.
legend
logical. Should a legend be included?
trace.label
overall label for the legend.
fixed
logical. Should the legend be in the order of the levels
of trace.factor or in the order of the traces at their right-hand ends?
xlab,ylab
the x and y label of the plot each with a sensible default.
ylim
numeric of length 2 giving the y limits for the plot.
lty
line type for the lines drawn, with sensible default.
col
the color to be used for plotting.
pch
a vector of plotting symbols or characters, with sensible
default.
xpd
determines clipping behaviour for the legend
used, see par(xpd). Per default, the legend is
not clipped at the figure border.
leg.bg, leg.bty
arguments passed to legend().
xtick
logical. Should tick marks be used on the x axis?
xaxt, axes, ...
graphics parameters to be passed to the plotting routines.
Details
By default the levels of 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 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 xlab, ylab, ylim,
lty, col and pch are given suitable defaults
(and xlim and xaxs are set and cannot be overridden).
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.
Note
Some of the argument names and the precise behaviour are chosen for
S-compatibility.
References
Chambers, J. M., Freeny, A and Heiberger, R. M. (1992)
Analysis of variance; designed experiments.
Chapter 5 of Statistical Models in S
eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Examples
require(graphics)
with(ToothGrowth, {
interaction.plot(dose, supp, len, fixed = TRUE)
dose <- ordered(dose)
interaction.plot(dose, supp, len, fixed = TRUE, col = 2:3, leg.bty = "o")
interaction.plot(dose, supp, len, fixed = TRUE, col = 2:3, type = "p")
})
with(OrchardSprays, {
interaction.plot(treatment, rowpos, decrease)
interaction.plot(rowpos, treatment, decrease, cex.axis = 0.8)
## order the rows by their mean effect
rowpos <- factor(rowpos,
levels = sort.list(tapply(decrease, rowpos, mean)))
interaction.plot(rowpos, treatment, decrease, col = 2:9, lty = 1)
})
with(esoph, {
interaction.plot(agegp, alcgp, ncases/ncontrols, main = "'esoph' Data")
interaction.plot(agegp, tobgp, ncases/ncontrols, trace.label = "tobacco",
fixed = TRUE, xaxt = "n")
})
## deal with NAs:
esoph[66,] # second to last age group: 65-74
esophNA <- esoph; esophNA$ncases[66] <- NA
with(esophNA, {
interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5)
# doesn't show *last* group either
interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5, type = "b")
## alternative take non-NA's {"cheating"}
interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5,
fun = function(x) mean(x, na.rm = TRUE),
sub = "function(x) mean(x, na.rm=TRUE)")
})
rm(esophNA) # to clear up
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(stats)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/stats/interaction.plot.Rd_%03d_medium.png", width=480, height=480)
> ### Name: interaction.plot
> ### Title: Two-way Interaction Plot
> ### Aliases: interaction.plot
> ### Keywords: hplot
>
> ### ** Examples
>
> require(graphics)
>
> with(ToothGrowth, {
+ interaction.plot(dose, supp, len, fixed = TRUE)
+ dose <- ordered(dose)
+ interaction.plot(dose, supp, len, fixed = TRUE, col = 2:3, leg.bty = "o")
+ interaction.plot(dose, supp, len, fixed = TRUE, col = 2:3, type = "p")
+ })
>
> with(OrchardSprays, {
+ interaction.plot(treatment, rowpos, decrease)
+ interaction.plot(rowpos, treatment, decrease, cex.axis = 0.8)
+ ## order the rows by their mean effect
+ rowpos <- factor(rowpos,
+ levels = sort.list(tapply(decrease, rowpos, mean)))
+ interaction.plot(rowpos, treatment, decrease, col = 2:9, lty = 1)
+ })
>
> with(esoph, {
+ interaction.plot(agegp, alcgp, ncases/ncontrols, main = "'esoph' Data")
+ interaction.plot(agegp, tobgp, ncases/ncontrols, trace.label = "tobacco",
+ fixed = TRUE, xaxt = "n")
+ })
> ## deal with NAs:
> esoph[66,] # second to last age group: 65-74
agegp alcgp tobgp ncases ncontrols
66 65-74 0-39g/day 30+ 0 2
> esophNA <- esoph; esophNA$ncases[66] <- NA
> with(esophNA, {
+ interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5)
+ # doesn't show *last* group either
+ interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5, type = "b")
+ ## alternative take non-NA's {"cheating"}
+ interaction.plot(agegp, alcgp, ncases/ncontrols, col = 2:5,
+ fun = function(x) mean(x, na.rm = TRUE),
+ sub = "function(x) mean(x, na.rm=TRUE)")
+ })
> rm(esophNA) # to clear up
>
>
>
>
>
> dev.off()
null device
1
>