# [R] setting xlim and ylim with asp=1

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 25 15:10:59 CEST 2003

```On Mon, 25 Aug 2003, Angel wrote:

> 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:
>
> xlim<-c(-1,1)
> ylim<-c(-1,2)
> xyratio=abs((xlim[1]-xlim[2])/(ylim[1]-ylim[2]))
> width<-par("pin")[1]
> height<-par("pin")[2]
> if (height>width/xyratio) height=width/xyratio else if(height<width/xyratio)
> width=height*xyratio
> par(pin=c(width,height))
>
> 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).

What _you_ wanted in one example is not necessarily the most logical or
useful.  Consider what would happen if you added new=TRUE?  I think you
have not grasped the logical order: the plot region is set before a user
coordinate system is set up (or changed).

We do expect people to read `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

```