Why does R\'s base plot function do this? We have to use points
or lines
, which needs special code rather than using the type
argument
Because plot.default
doesn't have an add
argument
> args(plot.default)
function (x, y = NULL, type = "p", xlim = NULL, ylim = NULL,
log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
ann = par("ann"), axes = TRUE, frame.plot = axes, panel.first = NULL,
panel.last = NULL, asp = NA, ...)
NULL
Those other functions are not overriding plot
but are providing their own methods, which do have an argument add
because they were written that way. Personally, having grown up with using points()
and lines()
etc I don't find them much extra work and I would use them in preference to a plot
method with an add
argument, although we've written both ways in packages that I contribute to.
As to why plot.default
doesn't have an add
argument? You'd have to ask R Core, but I can suggest some reasons
plot.default
is designed to generate an entire plot on the devicepoints()
and lines()
etc so why duplicate?plot.default
is simpler code without code to handle add
If add=TRUE
is not provided (and you are using base graphics) then use par(new=TRUE)
prior to the plot call. You will need to suppress the xlab, ylab and other stuff that might interfere or overlay existing annotation, and I did leave the ylab untouched to illustrate why that warning is needed. You also will need to set xlim and ylim to be the same.
plot(1:10);par(new=TRUE)
plot(10:1)
After reviewing the comments, my vote is for @John's point that a new plot
-call would perhaps have a different set of xlim and ylim, not to mention the possibility of overwriting all the text objects in the margins. points
and lines
do not have the facility to recalculate the limits of the plot area so they are "safe" to use with plot.default
.