Re: [R] panel.first problem when plotting with formula

From: David Winsemius <>
Date: Wed, 25 May 2011 18:42:24 -0400

On May 25, 2011, at 5:56 PM, Gene Leynes wrote:

> David, Peter (and others),
> If you're interested, I submitted this as a bug, and was informed of
> the error of my ways by Professor Ripley
> * His informative reply is copied below. *
> The short answer is that panel.first is not a documented function of
> "plot.formula", which is called by the generic "plot".

Apparently not the first time he has been called upon to do so. Here is a similar question, albeit with no answer (at least in Baron's archive) at that time.

(... the link to the ancient bug is broken.)

But plot.formula promises to pass "..." arguments to later "hand offs" and apparently it munges up the 'dots' in a manner that does not. In fact, plot.formula gets handed back to generic `plot`. Prof Ripley obviously has an understanding of the term `expression` that surpasses mine. Does your understaning of his reply extend to explaining why works with our naive invocation of panel.first while his suggested syntax does not:

plot(dat, panel.first=quote( bgfun() ) ) # Fails. plot(dat, panel.first= bgfun() ) # Succeeds.

So I it still appears there is a demonstrable degree of inconsistency, even if there is no "bug".

> The solution gives me some insight into how the lazy evaluation works.
> ## Note: It's still not a documented use of the function!
> plot(y ~ x, data=dat, panel.first=quote(bgfun()))
> On Wed, May 25, 2011 at 2:13 AM, <> wrote:
> Brian Ripley <> changed:
> What |Removed |Added
> ----------------------------------------------------------------------------
> Status|NEW |CLOSED
> Resolution| |INVALID
> --- Comment #1 from Brian Ripley <> 2011-05-25
> 03:13:34 EDT ---
> panel.first is not a documented argument to plot.formula: please do
> read the help.

Yes, I did read the help page. I also looked at the code (of plot.formula,, and plot.default) and made a good faith effort at following the flow of data through that code by inserting print and str statements at what appeared to be critical points so I could see where plot.formula was "going" and what it was being given to work with.

> It is a documented argument to plot.default(), as

> panel.first: an expression to be evaluated after the plot axes are set
> ^^^^^^^^^^
> but you passed an evaluated function call. It first ran bgfun() and
> then the
> plot call. It worked for plot.default() by lazy evaluation.

I also tried using just panel.first=bgfun as I would have with lattice calls, and it did not succeed in any application.

> You needed
> plot(y ~ x, data=dat, panel.first=quote(bgfun()))

David Winsemius, MD
West Hartford, CT

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 25 May 2011 - 22:45:05 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 May 2011 - 23:40:10 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive