Re: [R] Help on direction of axis in R needed

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Wed 11 Oct 2006 - 09:44:17 GMT

On Wed, 2006-10-11 at 02:27 -0700, Silvia Lipski wrote:
> Hi!
>
> I'd like to plot things with axes going from the
> highest to the lowest value, so that e.g. high values
> on the xaxis are plotted to the left and low values to
> the right.
> Could anyone tell me how this is done? I couldn't find
> anything in the documentation.
>
> Thanks a lot!
> Silli

Look at ?plot.default and in particular argument 'xlim', which take two settings, effectively from and to, (e.g. xlim = c(100, 1) will give x axis drawn from 100 on left to 1 on right)

plot(1:100, 1:100, xlim = c(175, 0))

Where we don't know the range of data explicitly, we can use for example range() to get the min and max of the data and then rev() to reverse these, as the example below shows:

xdat <- rnorm(100)
ydat <- runif(100)
plot(ydat ~ xdat, xlim = rev(range(xdat)))

The See Also section of ?plot would have pointed you to ?plot.default...

HTH G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC & ENSIS, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Oct 11 19:56:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 11 Oct 2006 - 10:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.