[Rd] [patch] add=TRUE in plot.default()
Andrew Clausen
clausen at econ.upenn.edu
Sun Mar 16 05:05:18 CET 2008
Hi Duncan,
On Mon, Mar 10, 2008 at 08:51:23AM -0400, Duncan Murdoch wrote:
> >The add parameter only interacts with other parameters superficially --
> >some parameters of "plot" (like log) are related to the shape of the axes,
> >and should be inherited from what is on the plot already.
>
> I'd say causing some parameters to be completely ignored without a
> warning is more than a superficial interaction.
Fair enough. I suppose you could inadvertantly put leave "add=TRUE" in some
code, and wonder why axes aren't getting drawn.
> Really, add=TRUE is not
> a great design: it would be better to say "plot methods draw a new
> plot" (so they need args for all the decorations like axes, titles,
> etc.), and have other ways to add things to plots.
I don't like the idea of having a separate way to add to plots.
I like the look of this code:
f <- function(x) x^2
g <- function(x) 1/x - 1
h <- function(x) x
functions <- c(f, g, h)
for (i in 1:length(functions))
plot(functions[[i]], add=i>1, col=i)
Of course, I'd prefer something like
plot.new()
for (i in 1:length(functions))
plot(functions[[i]], add=TRUE, col=i)
but that seems out of reach for compatibility reasons.
How would you write this code in R today?
> Hadley was right on
> this, his ggplot2 has a better thought-out design than classic graphics.
> However, we have what we have.
I'm sure ggplot2 is vastly better, although I couldn't find a quick intro.
(Typing "ggplot2 examples" into Google didn't help me.) Since plot() isn't
deprecated yet, it's worth making cheap useful improvements.
> >I agree. Adding an "add=FALSE" parameter to plot() would generate errors
> >for
> >methods that don't implement it, so they would all have to be changed
> >simultaneously, including in private/unreleased code.
> >
> >So I'd like to settle for second best: adding add=FALSE parameters to many
> >plot
> >methods.
>
> I like that suggestion better than adding it here and there, one at a
> time. So, to advance the discussion: can you take a look at the plot
> methods that are in the base and recommended packages, and work out how
> many already have it, how many would be improved if it was added, and in
> how many cases it just wouldn't make sense? (You could also do this on
> all the CRAN and Bioconductor packages, but that would be about 100
> times more work: about 50 times as many packages, and much less
> consistency in the programming and documentation standards. Maybe on a
> subset of popular ones, e.g. those that Rcmdr suggests?)
I had a quick look at the base packages. (I did a crude search with find and
grep on the R source tarball.) I attached the full list. There were 40 files
containing plot methods. Of these, 9 already implemented add=TRUE explicitly
and a further 9 inherited it from other plot methods that could or already do
implement it. There were 2 methods for which it clearly makes no sense. For
example, plot.lm makes no sense because it does several separate plots, one
after the other.
It looks reasonably straightforward to implement most of the remaining methods.
I must confess I don't understand what all of these plots are doing from a
statistics point of view, but I suppose this shouldn't matter. (Econometrics
uses different language...)
> Data like that could make a convincing argument that the effort of
> adding this to the base packages is worthwhile. (To get it added to
> non-base packages will require you to convince their maintainers that
> it's a good idea.) Another helpful part of the argument will be for you
> to volunteer to do the work of both code and documentation updates.
I'm not very excited about doing work outside of base. I can do the base
code + documentation though. Any volunteers?
Cheers,
Andrew
-------------- next part --------------
graphics/R/barplot.R already implemented
graphics/R/spineplot.R
graphics/R/boxplot.R already implemented
graphics/R/mosaicplot.R
graphics/R/sunflowerplot.R already implemented
graphics/R/datetime.R
graphics/R/coplot.R
graphics/R/hist.R implemented for plot.histogram, but not hist
graphics/R/plot.design.R
graphics/R/matplot.R already implemented
graphics/R/plot.R my patch :)
graphics/R/fourfoldplot.R
graphics/R/assocplot.R
graphics/R/cdplot.R
stats/R/ts.R has plot.type="multiple"
stats/R/biplot.R
stats/R/acf.R
stats/R/ppr.R inherited
stats/R/stl.R
stats/R/plot.lm.R multiple plots -- no sense
stats/R/qqplot.R inherited
stats/R/stepfun.R already implemented
stats/R/TukeyHSD.R
stats/R/dendrogram.R
stats/R/interaction.plot.R
stats/R/lag.plot.R
stats/R/monthplot.R already implemented
stats/R/ecdf.R already implemented (inherited from stepfun)
stats/R/spectrum.R already implemented
stats/R/nls-profile.R
stats/R/prcomp.R inherited
stats/R/termplot.R multiple plots -- no sense
stats/R/princomp-add.R
stats/R/isoreg.R
stats/R/hclust.R
stats/R/kernel.R inherited
stats/R/medpolish.R inherited
stats/R/HoltWinters.R inherited
stats/R/density.R inherited
splines/R/splineClasses.R inherited
More information about the R-devel
mailing list