You mentioned "the lm
class has some kind of interface defined for the plot()
function". In fact, this is a S3 mechanism in R, which follows "method.class" naming conventions. Here, the method is plot
and the class is lm
. You don't have to type plot.lm
in order to get these plots. When you call plot
, R will first examine the class type of the first argument, and fount it (m
in this case) to be of class lm
; then R automatically calls the plot.lm
function.
For the plot
method, you can see that it applies to more classes by typing methods(plot)
in R:
[1] plot.acf* plot.data.frame* plot.decomposed.ts* plot.default plot.dendrogram*
[6] plot.density plot.ecdf plot.factor* plot.formula* plot.function
[11] plot.gofm* plot.gofv* plot.hap.score* plot.hclust* plot.histogram*
[16] plot.HoltWinters* plot.isoreg* plot.lm plot.md plot.medpolish*
[21] plot.mlm plot.ppr* plot.prcomp* plot.princomp* plot.profile.nls*
[26] plot.spec plot.spline* plot.stepfun plot.stl* plot.table*
[31] plot.ts plot.tskernel* plot.TukeyHSD plot.xyVector*
Non-visible functions are asterisked
You see plot.lm
is one of them. To learn any one of these, you may use fix(plot.lm)
. Then you will notice at the first lines:
caption = list("Residuals vs Fitted",
"Normal Q-Q", "Scale-Location", "Cook's distance", "Residuals vs Leverage",
expression("Cook's dist vs Leverage " * h[ii]/(1 - h[ii])))
Obviously you'll know which plots are constructed when you call plot
on an object of class lm
:) Hope this helps!