Search code examples
rplotpar

Plot which parameter where in R?


So... I'm looking at an example in a book that goes something like this:

library(daewr)
mod1 <- aov(height ~ time, data=bread)
summary(mod1)
...
par(mfrow=c(2,2))
plot(mod1, which=5)
plot(mod1, which=1)
plot(mod1, which=2)
plot(residuals(mod1) ~ loaf, main="Residuals vs Exp. Units", font.main=1, data=bread)
abline(h = 0, lty = 2)

That all works... but the text is a little vague about the purpose of the parameter 'which='. I dug around in the help (in Rstudio) on plot() and par(), looked around online... found some references to a different 'which()'... but nothing really referring me to the purpose/syntax for the parameter 'which=' inside plot().

A bit later (next page, figures) I found a mention of using names(mod1) to view the list of quantities calculated by aov... which I presume is what which= is refering to, i.e. which item in the list to plot where in the 2x2 matrix of plots. Yay. Now where the heck is that buried in the docs?!?


Solution

  • which selects which plot to be displayed:

    1. A plot of residuals against fitted values
    2. A normal Q-Q plot
    3. A Scale-Location plot of sqrt(| residuals |) against fitted values
    4. A plot of Cook's distances versus row labels
    5. A plot of residuals against leverages
    6. A plot of Cook's distances against leverage/(1-leverage)

    By default, the first three and 5 are provided.

    Check ?plot.lm in r for more details.