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

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 25 May 2011 10:34:20 -0400

On May 24, 2011, at 11:42 PM, Gene Leynes wrote:

> Peter,
>
> Good idea! (why didn't I think of that?)
>
> If it stumped the r-list, I think there is probably a slight bug
> with the
> plot formula.
>
> Problems like this make me realize how amazingly full featured and
> relatively bug free R is. A problem like this would never happen in
> Excel,
> because this level of functionality does not exist. However, if it
> did, it
> would probably never be fixed... and you could substitute "Excel"
> with "Any
> commercial software".

plot(dat, panel.first=bgfun() ) # succeeds

So the problem is not with plot.data.frame.

So someplace in the processing of dots and the handoff to

do.call(funname, c(list(mf[[i]], y, ylab = yl, xlab = xl), dots))

... where funname = "plot", the dot identities do not get honored. The 'plot" function is where it all started, but the first argument is now mf[[i]], and is that is now a numeric vector. So I think it gets handed off to plot.default, which sets panel.first to NULL.

-- 
David.

>
> Gene
>
>
> On Tue, May 24, 2011 at 3:13 AM, Peter Ehlers <ehlers@ucalgary.ca>
> wrote:
>
>> On 2011-05-23 16:54, Gene Leynes wrote:
>>
>>> I wrote a little function called bgfun that adds gridlines and a
>>> background,
>>> but it's not working with I plot using the formula.
>>>
>>> I have some theories on what's happening, but even if my theory is
>>> right,
>>> I
>>> don't know how to fix it.
>>>
>>> Someone have a straightforward silver bullet?
>>>
>>
>> No silver bullet, but this seems to work:
>>
>> plot(y ~ x, data=dat, type="n")
>> points(y ~ x, data=dat, panel.first=bgfun())
>>
>> (I think that plot.formula may need a fix but
>> offhand I can't see whether that's easy or hard.)
>>
>> Peter Ehlers
>>
>>
>>> Thank you,
>>>
>>> Gene
>>>
>>>
>>>
>>> bgfun = function(color='honeydew2',linecolor='grey45',
>>> addgridlines=TRUE){
>>> tmp=par("usr")
>>> rect(tmp[1], tmp[3], tmp[2], tmp[4], col=color)
>>> if(addgridlines){
>>> ylimits=par()$usr[c(3,4)]
>>> abline(h=pretty(ylimits,10), lty=2, col=linecolor)
>>> }
>>> }
>>> dat = data.frame(x=1:10,y=1:10)
>>>
>>> ## Works
>>> plot(dat$x, dat$y, panel.first=bgfun())
>>>
>>> ## Why doesn't this work?
>>> plot(y ~ x, data=dat, panel.first=bgfun())
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD West Hartford, CT ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Wed 25 May 2011 - 14:36:43 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 Thu 26 May 2011 - 01:10:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive