[R] Getting plot axes where they should be!

(Ted Harding) Ted.Harding at manchester.ac.uk
Mon Jul 21 14:13:48 CEST 2008

Hi Folks,
I've been digging for the solution to this for several
hours now. If there is a solution, it must be one of the
worst "needle-in-a-haystack" examples in R documentation!

Essentially, I want to make an x-y plot in which the
X-axis really is the X-axis (i.e. its vertical position
is at y=0), and the Y-axis really is the Y-axis (i.e.
its horizontal position is at x=0). Discussion, with
toy examples, below.

I have sort-of solved this (as stated) for one special
case, after a depth-4 search through

  ?plot --> ?plot.default --> ?par --> ?axis

which finally led me to the parameter "pos" to axis():

  pos: the coordinate at which the axis line is to be drawn:
  if not 'NA' this overrides the values of both 'line' and 'mgp[3]'.

Hence, instead of


(where the axes do not meet at the origin (0,0)), I can do


which is *exactly* what I want in this case.

But now I want to do the same, where instead of plotting the
two points (0.5,0.5), (2.5,2.5) I want to plot (0.5,2.5), (2.5,4.5).

Provided I keep the xlim and ylim to both have lower value 0,
a similar solution again works fine:


But, in this case, what I *really* want is to limit the Y range
to the "relevant" bit: ylim=c(2,5) -- I don't want to have a lot
of empty space below the points. So I want a Y-axis running from
y=2 to y=5, and X-axis as before from x=0 to x=3, and I want these
two axes to meet at (x=0,y=2). But how?

By analogy to the above, I need to set a "pos=0" for the X-axis,
and a "pos=2" for the y-axis. And I have not been able to discover
how to do this.

With thanks,

E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 21-Jul-08                                       Time: 13:13:45
------------------------------ XFMail ------------------------------

More information about the R-help mailing list