Re: [S] a better box()?

Christian Keller (ckeller@aicos.com)
Fri, 04 Sep 1998 09:53:04 +0200


Greg Tucker-Kellogg <GTuckerKellogg@genetics.com> wrote:

>> The simple S function box() does
>> not work as I would expect when
>> plots have logarithmic axes. I
>> know the par()$usr values are
>> modified when a plot is
>> logarithmic, but shouldn't such a
>> simple function as box() have
>> enough information to work as
>> expected?
>>
>> [snipped]
>>
>> Is there some component of par()
>> that could be used by a better
>> box() to draw boxes correctly in
>> the case of logaritmic axes?

Yes there is: par("xaxt") and par("yaxt").
So, a simple fix would be:
(I assume that the S-Plus expert has a more elegant solution.)

mybox <- function(n = 1, fill = F, ...)
{
oldpar <- par(exp = 1, ...)
if(fill) {
usr <- par("usr")
if(par("xaxt")=="l") usr[1:2] <- 10^usr[1:2]
if(par("yaxt")=="l") usr[3:4] <- 10^usr[3:4]
polygon(x = usr[c(1, 2, 2, 1)], y = usr[c(3, 3, 4, 4)])
}
else .Fortran("bboxz",
as.integer(n))
par(oldpar)
invisible()
}

[This is the modified box() in version 3.4 for Sun SPARC]

which will give the expected result for logarithmic axes.

plot(c(10,1000),c(10,1000))
mybox(fill=T, col=2)

plot(c(10,1000),c(10,1000),log='x')
mybox(fill=T, col=2)

plot(c(10,1000),c(10,1000),log='y')
mybox(fill=T, col=2)

plot(c(10,1000),c(10,1000),log='xy')
mybox(fill=T, col=2)

----------------------------------------------------------
Christian Keller Tel: +41 61 686 98 81
AICOS Technologies AG Fax: +41 61 686 98 88
Efringerstrasse 32 email: ckeller@aicos.com
CH-4057 Basel, Switzerland Web: http://www.aicos.com/
----------------------------------------------------------
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news