Skip to main content

3.3) Understanding Methods


The diverse capabilities of plot() are possible because it’s actually a generic ‘umbrella’ for a range of functions called methods (with full names like plot.factor) that can be invoked according to the class of the object supplied for the first argument. To find the full range of methods available, type methods(plot), or browse function names beginning ‘plot.’. In the exercise below, plot() is given an entire data frame as its object (so plot.data.frame() is automatically invoked); in the following section we will supply a linear model (and get plot.lm()). You can also specify a formula just by using the tilda symbol ~ (e.g. plot(y ~ x)). Type ?plot.default and you’ll actually get a more helpful help file that shows some common arguments such as type=, xlab= and ylab=, which are worth remembering.

Some other generic 'umbrella' functions with many different methods are summary(), as() and print().

In the basic plot() help file, the only other argument mentioned is .... This stands for 'arguments to be passed to methods, such as graphical parameters'. This means you can supply plot() with extra arguments that are specified in the relevant ‘plot.’ method functions. In fact, when you go to the help files for the methods you’ll find they also have ... in their arguments lists! Here it explains that any extra arguments that are still not defined should refer to 'graphical parameters' in the function par(). And so on...