[R] controlling plot range

Marc Schwartz marc_schwartz at comcast.net
Fri Oct 19 20:04:44 CEST 2007


Bert et al,

A point of clarification. If one reads ?par, one will note [emphasis
added]:


There are several parameters can **only** be set by a call to par():

      * "ask",
      * "fig", "fin",
      * "lheight",
      * "mai", "mar", "mex", "mfcol", "mfrow", "mfg",
      * "new",
      * "oma", "omd", "omi",
      * "pin", "plt", "ps", "pty",
      * "usr",               
      * "xlog", "ylog"

The remaining parameters can also be set as arguments (often via ...) to
high-level plot functions such as ...


Thus, par("usr") at least by documentation, cannot be set using it
'inline' in a plot function call as John has attempted here.

HTH,

Marc Schwartz



On Fri, 2007-10-19 at 10:49 -0700, Bert Gunter wrote:
> John:
> 
> I agree: the Docs are not clear on this. V&R's MASS (p.84 in the 4th
> edition) gives an explanation:
> 
> "Positions in the plot region may also be specified in absolute **user
> coordinates**.  Initially user coordinates and relative coordinates
> [..relative to the unit square of the enclosing region--BG] coincide,, but
> any high-level plotting function changes the user coordinates so that the x-
> and y- coordinates range from their minimum to maximum values as given by
> the plot axes."
> 
> As James said, xlim and ylim is what you want. A more extensive discussion
> and examples of the use of usr coordinates can be found in Paul Murrell's R
> GRAPHICS book, pp. 99 -105.
> 
> Bert Gunter
> Genentech Nonclinical Statistics
> 
> 
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of James
> Sent: Friday, October 19, 2007 10:01 AM
> To: John Sorkin
> Cc: r-help at r-project.org
> Subject: Re: [R] controlling plot range
> 
> On Oct 19, 2007, at 10:54 AM, John Sorkin wrote:
> 
> > Windows XP
> > R 2.5.0
> > I am trying to produce two plots that have the same range, i.e. x  
> > from 50 to 400 on both plots and y from 50 to 400 on both plots.  
> > (This will allow me to compare slopes). I have used the code below  
> > without success using usr (I have also used xaxp and yaxp but I am  
> > not including the code):
> >
> > plot(tgNo26[,"TGh"],tgNo26[,"TGs"],usr=c(50,400,50,400))
> > plot(tgNo26[grep("CONTROL",tgNo26[,"PATIENT"]),"TGh"],
> >      tgNo26[grep("CONTROL",tgNo26[,"PATIENT"]),"TGs"],usr=c 
> > (50,400,50,400))
> >
> > RESULT:
> > axes on first plot 50-400, y axis 50-350
> > axes on second plot 50-250 y axis 100-250
> 
> From
> 
> ?plot.default
> 
> Are you looking for:
> 
> xlim		the x limits (x1, x2) of the plot. Note that x1 > x2 is
> allowed  
> and leads to a "reversed axis".
> ylim		the y limits of the plot.
> 
> I believe this will allow you to set the axes to the same limits so  
> that you can compare more easily.
> 
> HTH
> 
> James



More information about the R-help mailing list