[R] Unspecified [upper] xlim/ylim?

(Ted Harding) Ted.Harding at manchester.ac.uk
Tue Jun 15 21:55:29 CEST 2010


On 15-Jun-10 19:35:54, Marc Schwartz wrote:
> On Jun 15, 2010, at 12:11 PM, Ted Harding wrote:
> 
>> On 15-Jun-10 16:01:24, William Dunlap wrote:
>>>> -----Original Message-----
>>>> From: r-help-bounces at r-project.org 
>>>> [mailto:r-help-bounces at r-project.org] On Behalf Of 
>>>> Ted.Harding at manchester.ac.uk
>>>> Sent: Tuesday, June 15, 2010 8:49 AM
>>>> To: r-help at stat.math.ethz.ch
>>>> Subject: [R] Unspecified [upper] xlim/ylim?
>>>> 
>>>> Greetings!
>>>> I would like to be able to specify a fixed (say) lower limit
>>>> for plotting, while leaving the upper limit "floating, when
>>>> plotting. The context is that the maximum in the data to be
>>>> plotted is unpredictable, being the consequence of a simulation,
>>>> whereas I know that it cannot be less than (say) 0; and I want
>>>> to fix the lower limit at 0 in any plot, leaving the upper limit
>>>> to be assigned by plot() as a result of the computed values.
>>>> 
>>>> I know I can do this by determining the max() of the data, and
>>>> then computing a "Ymax" to put in (say) ylim = c(0,Ymax). However,
>>>> for certain reasons, I would prefer not to have to do this.
>>>> (And it's just a preference ... ).
>>>> 
>>>> Whereas one can leave the whole issue of setting both plotting
>>>> limits to plot(), by not specifying ylim (or xlim), or one can
>>>> explcitily specify both the upper and lower limits by (say)
>>>> ylim=c(Ymin,Ymax), there seems to be no way of fixing one and
>>>> leaving the other floating so that plot() would do its own thing.
>>>> 
>>>> ylim requires two numbers to be given. Things like ylim=c(0,)
>>>> or ylim=c(0,NA) would generate an error.
>>> 
>>> Currently ylim=c(yValueAtBottomOfPlot, yValueAtTopOfPlot), not
>>> c(yMin,yMax).  E.g., ylim=c(10,0) means to reverse the y axis,
>>> with 0 at the top and 10 at the bottom.  Putting an NA into
>>> ylim seems attractive but doesn't it run into problems because
>>> ylim doesn't mean c(yMin,yMax)?
>>> 
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com  
>>> 
>>>> 
>>>> Am I chasing a phantom? Or is there a way?
>>>> Thanks
>>>> Ted.
>> 
>> Sorry, Bill, but you've misunderstood what I mean by "Ymin" and
>> "Ymax".
>> As explained, these are notations for values which I either compute,
>> or choose, to put in as the arguments in ylim=c(... , ...). YMin and
>> Ymax would be such as to ensure that the range of the axis included
>> at least the range (Ymin,Ymax) (or, depending on the choice, possibly
>> to exclude certain values from the plot).
>> 
>> So, indeed, ylim does mean c(Ymin,Tmax).
>> 
>> Ted.
> 
> Ted, perhaps I am being dense here (always a possibility),

You're not the only one ...

> but by
> default if, for example, 'ylim' is unspecified, plot() essentially uses
> range(YVals) as the min/max values for the Y axis. Also, by default,
> with par(yaxs = "r"), the Y axis range is extended by 4% in both
> directions. Same for the x axis range.
> 
> Here is the snippet of relevant code from plot.default() for 'ylim':
> 
>   ylim <- if (is.null(ylim)) 
>      range(xy$y[is.finite(xy$y)])
>   else ylim
> 
> Thus, if you want to explicitly specify the low end of the range for
> the Y axis and have the upper end of the range left to the default
> methodology, you would indeed use:
> 
>   ylim = c(0, max(YVals))
> 
> as the argument syntax. The same would apply for the x axis limits.
> 
> Is that what you are after?
> 
> HTH,
> Marc Schwartz

It does! And I could indeed have found it by the command "plot.default"
and getting the listing. Thanks, Marc, for lifting the lid!
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 15-Jun-10                                       Time: 20:55:26
------------------------------ XFMail ------------------------------



More information about the R-help mailing list