[R] setting xlim and ylim with asp=1

Angel angel_lul at hotmail.com
Mon Aug 25 14:58:34 CEST 2003

Thanks for the advise. Sorry, I should have explained better.
As you say xlim and ylim have an effect. But when they do not match the
width and height of the plot region , one of them is modified in order to
make the plot fill the whole plot region with the aspect ratio given.
I would have expected that because I give asp, xlim and ylim, then the plot
region would be automatically modified.
After reading An Introduction to R, I would have expected R to automatically
do something like:

if (height>width/xyratio) height=width/xyratio else if(height<width/xyratio)

And, now, I get what I wanted:
plot(boxxy,type="l",xaxs="i",yaxs="i",xlim=c(-1,1), ylim=c(-1,2),asp=1)

That was exactly what I actually wanted to do.

Obviously, because I am setting the aspect ratio through par("pin"), now I
get the same plot without the asp option.
plot(boxxy,type="l",xaxs="i",yaxs="i",xlim=c(-1,1), ylim=c(-1,2))

I though I could ask why this is not done automatically, from my point of
view, the most sensible thing would be that if I give asp, xlim and ylim
then the plot region is modified to satisfy them (and not xlim or ylim
modified to satisfy the plot region defaults).
Anyway, thanks for the advice.

----- Original Message -----
From: "Prof Brian Ripley" <ripley at stats.ox.ac.uk>
To: "Angel" <angel_lul at hotmail.com>
Cc: <r-help at stat.math.ethz.ch>
Sent: Monday, August 25, 2003 1:31 PM
Subject: Re: [R] setting xlim and ylim with asp=1

> On Mon, 25 Aug 2003, Angel wrote:
> > In plot(), when using option asp=1 the xlim and ylim have no effect
> > they are changed
> > changed in order to fill the whole plot region.
> Not true: try xlim=c(-2,2) in your example.
> > Is there a way to
> > automatically set
> > xlim and ylim when asp has been set to 1?
> > For example:
> > #This is a box of the plot ranges I want:
> > boxxy=rbind(c(-1,2),c(-1,-1),c(1,-1),c(1,2),c(-1,2))
> > #Without asp=1 I get what I want (i.e. I can't see the box because it
> > #overlays with the axis
> > plot(boxxy,type="l",xaxs="i",yaxs="i",xlim=c(-1,1), ylim=c(-1,2))
> > # When I add asp=1 I can see the box
> > plot(boxxy,type="l",xaxs="i",yaxs="i",xlim=c(-1,1), ylim=c(-1,2),asp=1)
> And you must be able to, since the plot region is not in ratio 2:3 on any
> standard graphics device.
> R is doing sensible things, and you have not told us what you want, just
> made a false assertion.  Perhaps you could try to explain what it is you
> actually want to do?
> You cannot set the aspect ratio, the plot region and xlim and ylim
> simultaneously: once you have three the fourth is (partially) determined.
> I suspect you intended to set the plot region ... see An Introduction to
> R.
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list