[R] Reverse plot axes with xlim=rev(range(x)) fails with asp=1

Gregory Jefferis gsxej2 at cam.ac.uk
Sat Mar 5 19:07:18 CET 2005


Dear R users,

I would like to reverse the axes on some xy plots (for example to set the
origin at the top left rather than the bottom left).  I had planned to use
something of the following form:

plot(y=y<-c(20,4,5,6),x=x<-c(10,20,30,40),ylim=rev(range(y)))

ie reversing ylim to reverse the y axis.  This works fine however I also
want to use the parameter asp=1 to ensure that equal distances in the x or y
direction are plotted as such on the screen.  However the simple example I
showed above now fails:

> plot(y=y<-c(20,4,5,6),x=x<-c(10,20,30,40),ylim=rev(range(y)),asp=1)

The actual ylim used is considerably less than it should be, so no points
appear on the plot.

Can anyone suggest a simple remedy?

Many thanks,

Greg Jefferis.

PS I would guess that the origin of this behaviour is that plot.window
expects xlim (and ylim) to be in the order xmin,xmax (or ymin,ymax) when it
sets about redefining xlim and ylim if asp!=NA.  If that suggestion is
correct, I'm not quite sure why the restriction is necessary.

-- 
Gregory Jefferis, PhD                               and:
Research Fellow
Department of Zoology                               St John's College
Downing Street                                      Cambridge
Cambridge, CB2 3EJ                                  CB2 1TP




More information about the R-help mailing list