[R] controlling plot range
John Sorkin
jsorkin at grecc.umaryland.edu
Sat Oct 20 01:59:53 CEST 2007
Thank you Bert, Marc, James
You have all pointed out that I can use xlim and ylim.
As Bert pointed out, the documentation is not as clear as it might be about this. Perhaps the R development team would consider modifying the help page.
As Marc points out, the documentation does say that usr can only be set by par. Perhaps the R development team would consider modifying the code of plot to check for the usr parameter, and if found print an error message.
Many thanks to Bert, Marc and James for their helpful suggestions and the R development team for creating R.
John
John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence
University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
jsorkin at grecc.umaryland.edu
>>> Marc Schwartz <marc_schwartz at comcast.net> 10/19/07 1:04 PM >>>
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
Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}
More information about the R-help
mailing list