Re: [R] Specifying relative position of text in a plot

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 12 Mar 2008 12:42:49 -0600

To left justify the text rather than center, use the adj argument, this is easier and probably more reliable than trying to adjust the x coordinate manually.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111
 
 


> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Nordlund,
> Dan (DSHS/RDA)
> Sent: Wednesday, March 12, 2008 12:26 PM
> To: Alberto Monteiro; Tom La Bone; r-help_at_r-project.org
> Subject: Re: [R] Specifying relative position of text in a plot
>
> > -----Original Message-----
> > From: r-help-bounces_at_r-project.org
> > [mailto:r-help-bounces_at_r-project.org] On Behalf Of Alberto Monteiro
> > Sent: Wednesday, March 12, 2008 10:28 AM
> > To: Tom La Bone; r-help_at_r-project.org
> > Subject: Re: [R] Specifying relative position of text in a plot
> >
> >
> > Tom La Bone asked:
> > >
> > > What is the simplest way to specify the location of text in a
> > > scatter plot (created using the plot function) in relative terms
> > > rather than specific x-y coordinates? For example, rather than
> > > putting text at
> > > (300,49) on a plot, how do I put it 1/10 of the way over
> from the y
> > > axis and 1/2 of the way up from the x axis? Thanks.
> > >
> > See the help of par:
> > ?par
> >
> > Namely:
> >
> > plot(rnorm(100), rnorm(100))
> > pu <- par()$usr
> > x <- pu[1] * 0.5 + pu[2] * 0.5
> > y <- pu[3] * 0.1 + pu[4] * 0.9
> > text(x, y, "the quick brown fox jumps over a lazy dog")
> >
> > Alberto Monteiro
> >
>
> This is a useful example of placing text, but I interpreted
> the request as aking for the text to be placed at the left
> side of the graph (1/10 of the x range) and centered
> vertically (with respect to the y scale). So, then I would
> calculate x and y as
>
> x <- pu[1] * 0.9 + pu[2] * 0.1
> y <- pu[3] * 0.5 + pu[4] * 0.5
>
> Also, text() centers the supplied text at the x,y
> coordinates. So, if Tom wants the text "begin" at that point,
> he will need to adjust the x coordinate for the length of the
> string being printed.
>
> Hope this is helpful,
>
> Dan
>
> Daniel J. Nordlund
> Research and Data Analysis
> Washington State Department of Social and Health Services

> Olympia, WA 98504-5204
>
>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Wed 12 Mar 2008 - 18:55:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Mar 2008 - 19:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive