Plot univariate effects of one or more factors,
typically for a designed experiment as analyzed by aov().
Usage
plot.design(x, y = NULL, fun = mean, data = NULL, ...,
ylim = NULL, xlab = "Factors", ylab = NULL,
main = NULL, ask = NULL, xaxt = par("xaxt"),
axes = TRUE, xtick = FALSE)
Arguments
x
either a data frame containing the design factors and
optionally the response, or a formula or
terms object.
y
the response, if not given in x.
fun
a function (or name of one) to be applied to each
subset. It must return one number for a numeric (vector) input.
data
data frame containing the variables referenced by x
when that is formula-like.
...
graphical parameters such as col,
see par.
ylim
range of y values, as in plot.default.
xlab
x axis label, see title.
ylab
y axis label with a ‘smart’ default.
main
main title, see title.
ask
logical indicating if the user should be asked before a new
page is started – in the case of multiple y's.
xaxt
character giving the type of x axis.
axes
logical indicating if axes should be drawn.
xtick
logical indicating if ticks (one per factor) should
be drawn on the x axis.
Details
The supplied function will be called once for each level of each
factor in the design and the plot will show these summary values. The
levels of a particular factor are shown along a vertical line, and the
overall value of fun() for the response is drawn as a
horizontal line.
Note
A big effort was taken to make this closely compatible to the S
version. However, col (and fg) specifications have
different effects.
In S this was a method of the plot generic function for
design objects.
Author(s)
Roberto Frisullo and Martin Maechler
References
Chambers, J. M. and Hastie, T. J. eds (1992)
Statistical Models in S.
Chapman & Hall, London, thewhite book, pp. 546–7 (and 163–4).
Freeny, A. E. and Landwehr, J. M. (1990)
Displays for data from large designed experiments;
Computer Science and Statistics: Proc. 22nd Symp. Interface, 117–126,
Springer Verlag.
See Also
interaction.plot for a ‘standard graphic’
of designed experiments.
Examples
require(stats)
plot.design(warpbreaks) # automatic for data frame with one numeric var.
Form <- breaks ~ wool + tension
summary(fm1 <- aov(Form, data = warpbreaks))
plot.design( Form, data = warpbreaks, col = 2) # same as above
## More than one y :
utils::str(esoph)
plot.design(esoph) ## two plots; if interactive you are "ask"ed
## or rather, compare mean and median:
op <- par(mfcol = 1:2)
plot.design(ncases/ncontrols ~ ., data = esoph, ylim = c(0, 0.8))
plot.design(ncases/ncontrols ~ ., data = esoph, ylim = c(0, 0.8),
fun = median)
par(op)
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(graphics)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/graphics/plot.design.Rd_%03d_medium.png", width=480, height=480)
> ### Name: plot.design
> ### Title: Plot Univariate Effects of a Design or Model
> ### Aliases: plot.design
> ### Keywords: hplot
>
> ### ** Examples
>
> require(stats)
> plot.design(warpbreaks) # automatic for data frame with one numeric var.
>
> Form <- breaks ~ wool + tension
> summary(fm1 <- aov(Form, data = warpbreaks))
Df Sum Sq Mean Sq F value Pr(>F)
wool 1 451 450.7 3.339 0.07361 .
tension 2 2034 1017.1 7.537 0.00138 **
Residuals 50 6748 135.0
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> plot.design( Form, data = warpbreaks, col = 2) # same as above
>
> ## More than one y :
> utils::str(esoph)
'data.frame': 88 obs. of 5 variables:
$ agegp : Ord.factor w/ 6 levels "25-34"<"35-44"<..: 1 1 1 1 1 1 1 1 1 1 ...
$ alcgp : Ord.factor w/ 4 levels "0-39g/day"<"40-79"<..: 1 1 1 1 2 2 2 2 3 3 ...
$ tobgp : Ord.factor w/ 4 levels "0-9g/day"<"10-19"<..: 1 2 3 4 1 2 3 4 1 2 ...
$ ncases : num 0 0 0 0 0 0 0 0 0 0 ...
$ ncontrols: num 40 10 6 5 27 7 4 7 2 1 ...
> plot.design(esoph) ## two plots; if interactive you are "ask"ed
>
> ## or rather, compare mean and median:
> op <- par(mfcol = 1:2)
> plot.design(ncases/ncontrols ~ ., data = esoph, ylim = c(0, 0.8))
> plot.design(ncases/ncontrols ~ ., data = esoph, ylim = c(0, 0.8),
+ fun = median)
> par(op)
>
>
>
>
>
> dev.off()
null device
1
>