Why doesn't the plot respect add = TRUE?

Why does the base plot function R do this? We must use points or lines , which requires special code, not the type argument.

 plot(1:10) plot(10:1, add = TRUE) Warning messages: 1: In plot.window(...) : "add" is not a graphical parameter 2: In plot.xy(xy, type, ...) : "add" is not a graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) : 

Etc.

Many packages provide methods for (for example, "overriding") the graph and provide obvious ability to build (obj, add = TRUE) if obj belongs to the corresponding class. (Examples: sp , raster , spatstat .)

Is there any reason plot.default doesn't exist yet?

EDIT: This has been discussed in detail here:

http://tolstoy.newcastle.edu.au/R/e4/devel/08/03/0725.html

DM effectively answers it here: http://tolstoy.newcastle.edu.au/R/e4/devel/08/03/0734.html

+7
r
source share
2 answers

Because plot.default has no 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 

These other functions do not override plot , but provide their own methods, which have the add argument, because they were written that way. Personally, I grew up using points() and lines() , etc. I do not find them much extra work, and I would use them in the plot preference with the add argument, although we wrote both paths in the packages to which I contribute.

Why plot.default n't plot.default have an add argument? You should ask R Core, but I can offer some reasons.

  • plot.default designed to generate the entire graph on the device.
  • There are already points() and lines() , etc., so why duplicate?
  • plot.default is simple code without code to handle add
  • Backward compatible with S / S-Plus
+12
source share

If add = TRUE is not provided (and you are using basic graphics), use par(new=TRUE) before calling the plot. You will need to suppress xlab, ylab and other things that might interfere with or overlay the existing annotation, and I left ylab untouched to illustrate why this warning is needed. You will also need to set xlim and ylim so that they are the same.

  plot(1:10);par(new=TRUE) plot(10:1) 

enter image description here

After reviewing the comments, my vote for @John indicates that the new plot -call might have a different set of xlim and ylim, not to mention the possibility of overwriting all text objects in the fields. points and lines do not have the ability to recalculate the boundaries of the chart area so that they are "safe" for use with plot.default .

+10
source share

All Articles