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

From: Gregory Jefferis <gsxej2_at_cam.ac.uk>
Date: Sun 06 Mar 2005 - 05:07:18 EST


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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sun Mar 06 05:14:21 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:41 EST