[R] panel.first problem when plotting with formula

David Winsemius dwinsemius at comcast.net
Thu May 26 00:42:24 CEST 2011


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.

http://finzi.psych.upenn.edu/Rhelp10/2009-September/210328.html

(... 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  
plot.data.frame 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 plot.data.frame 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, <r-bugs at r-project.org> wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14591
>
> Brian Ripley <ripley at stats.ox.ac.uk> changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>             Status|NEW                         |CLOSED
>         Resolution|                            |INVALID
>
> --- Comment #1 from Brian Ripley <ripley at stats.ox.ac.uk> 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, plot.data.frame, 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



More information about the R-help mailing list