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(): ?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 plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), frame.plot=FALSE) (where the axes do not meet at the origin (0,0)), I can do plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), frame.plot=FALSE,pos=0) 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: plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(0,5), frame.plot=FALSE,pos=0) 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, Ted. -------------------------------------------------------------------- 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 ------------------------------

on 07/21/2008 07:13 AM (Ted Harding) wrote:> 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(): > > ?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 > > plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), > frame.plot=FALSE) > > (where the axes do not meet at the origin (0,0)), I can do > > plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), > frame.plot=FALSE,pos=0) > > which is *exactly* what I want in this case.Ted, try this: plot(c(0.5,2.5), c(0.5,2.5), xlim=c(0,3), ylim=c(0,3), xaxs = "i", yaxs = "i") or perhaps this: plot(c(0.5,2.5), c(0.5,2.5), xlim=c(0,3), ylim=c(0,3), xaxs = "i", yaxs = "i", axes = FALSE, frame.plot = FALSE) axis(1) axis(2)> 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: > > plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(0,5), > frame.plot=FALSE,pos=0)Same thing here: plot(c(0.5,2.5), c(2.5,4.5), xlim=c(0,3), ylim=c(0,5), xaxs = "i", yaxs = "i")> 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?plot(c(0.5,2.5), c(2.5,4.5), xlim=c(0,3), ylim=c(2,5), xaxs = "i", yaxs = "i")> 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, > Ted.See ?par and take note of ''xaxs'' and ''yaxs'', where it is noted that the default ''r'' extends the axes by +/- 4% of the data range. Using ''i'' gives you axes with the exact range of the data and/or the ''xlim'' and ''ylim'' settings. HTH, Marc Schwartz

On 7/21/2008 8:13 AM, (Ted Harding) wrote:> 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(): > > ?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 > > plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), > frame.plot=FALSE) > > (where the axes do not meet at the origin (0,0)), I can do > > plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), > frame.plot=FALSE,pos=0) > > 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: > > plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(0,5), > frame.plot=FALSE,pos=0) > > 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.It may or may not be possible in a single call to plot(), but it is certainly straightforward if you use separate calls to plot() and axis: > plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(2,5), axes=F) > axis(1, pos=2) > axis(2, pos=0) Generally speaking I find it is usually easier not to try to convince plot() to do strange things: I tell it to do nothing, and do the strange things myself. Duncan Murdoch

On 21-Jul-08 12:25:32, Marc Schwartz wrote:> on 07/21/2008 07:13 AM (Ted Harding) wrote: >> 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(): >> >> ?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 >> >> plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), >> frame.plot=FALSE) >> >> (where the axes do not meet at the origin (0,0)), I can do >> >> plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), >> frame.plot=FALSE,pos=0) >> >> which is *exactly* what I want in this case. > > Ted, try this: > > plot(c(0.5,2.5), c(0.5,2.5), xlim=c(0,3), ylim=c(0,3), > xaxs = "i", yaxs = "i") > > or perhaps this: > > plot(c(0.5,2.5), c(0.5,2.5), xlim=c(0,3), ylim=c(0,3), > xaxs = "i", yaxs = "i", axes = FALSE, frame.plot = FALSE) > > axis(1) > axis(2) > > >> 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: >> >> plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(0,5), >> frame.plot=FALSE,pos=0) > > Same thing here: > > plot(c(0.5,2.5), c(2.5,4.5), xlim=c(0,3), ylim=c(0,5), > xaxs = "i", yaxs = "i") > > >> 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? > > plot(c(0.5,2.5), c(2.5,4.5), xlim=c(0,3), ylim=c(2,5), > xaxs = "i", yaxs = "i") > >> 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, >> Ted. > > See ?par and take note of ''xaxs'' and ''yaxs'', where it is noted that the > default ''r'' extends the axes by +/- 4% of the data range. Using ''i'' > gives you axes with the exact range of the data and/or the ''xlim'' and > ''ylim'' settings. > > HTH, > Marc SchwartzThanks, Marc! Those hints solved it for me in the end. In fact, a variant on your suggestions is exactly what I want (in the third example): plot(c(0.5,2.5), c(2.5,4.5), xlim=c(0,3), ylim=c(2,5), xaxs = "i", yaxs = "i",frame.plot=FALSE) I have to say (admit? confess?) that I had read through the help on xaxs and yaxs in ?par, without interpreting it in terms of how the axis itself is positioned -- as written, it rather seems to describe how the annotations are computed and (in the case where xlim/ylim is not given) how long the axis should be. In other words, what are the properties of the axis itself (including its labels) rather than how it is offset perpendicular to itself (which is the issue I was trying to resolve). Re-reading it now that I have your solution, I still find that this interpretation is not explicit, and needs to be guessed. Thanks again, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 21-Jul-08 Time: 13:52:53 ------------------------------ XFMail ------------------------------

On 21-Jul-08 12:43:47, Duncan Murdoch wrote:> On 7/21/2008 8:13 AM, (Ted Harding) wrote: >> 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(): >> >> ?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 >> >> plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), >> frame.plot=FALSE) >> >> (where the axes do not meet at the origin (0,0)), I can do >> >> plot(c(0.5,2.5),c(0.5,2.5),xlim=c(0,3),ylim=c(0,3), >> frame.plot=FALSE,pos=0) >> >> 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: >> >> plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(0,5), >> frame.plot=FALSE,pos=0) >> >> 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. > > It may or may not be possible in a single call to plot(), but it is > certainly straightforward if you use separate calls to plot() and axis: > > > plot(c(0.5,2.5),c(2.5,4.5),xlim=c(0,3),ylim=c(2,5), axes=F) > > axis(1, pos=2) > > axis(2, pos=0)Thanks, Duncan! That nicely rounds off Marc''s response, and makes sense (and also, in fact, exposes my "blind spot" when I was reading the documentation in the first place).> Generally speaking I find it is usually easier not to try to convince > plot() to do strange things: I tell it to do nothing, and do the > strange things myself.It depends what you mean by "strange", Duncan. To be frank, I find R''s default "offset" axes to be strange, and what I''ve been trying to achieve to be "normal". But that''s a matter of taste, I suppose -- unless you need, for instance, to be able to lay a ruler over the plot and see where it meets the "axis"!> Duncan MurdochTed. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 21-Jul-08 Time: 14:00:58 ------------------------------ XFMail ------------------------------