[R] Add coordinates at specific points...

Greg Snow Greg.Snow at imail.org
Fri Jul 15 03:30:22 CEST 2011


To add to what David and Duncan wrote: If you want to plot something at a point where the x coordinate is in user coordinates, but the y-coordinate is something like the middle of the plot, or 1/5th of the way from the top then you can use the grconvertY function along with the text function.

If you are going to have several labels and want to plot them so that they do not overlap then there are functions in the plotrix and TeachingDemos packages that can be used to spread labels.

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of David Winsemius
Sent: Wednesday, July 13, 2011 6:11 PM
To: JIA Pei
Cc: r-help at r-project.org
Subject: Re: [R] Add coordinates at specific points...


On Jul 13, 2011, at 7:59 PM, JIA Pei wrote:

>
> Thanks David, for your prompt reply.
> Ok... just avoid this mess.
> I'd love to emphasize the key point M(2.1, sin(2.1)), and just write  
> a point coordinate by the side of M .How to do that easily?

Have you worked through the examples on the help(text) page? This does  
not seem to be that difficult. Three essential arguments.... x,y and  
text. You are supposed to put for effort and show what code you have  
tried.

text(2.1, sin(2.1), labels="M=(2.1, sin(2.1) )")

You can play around with the positioning arguments, which IIRC are  
adj= and <something else>.

> By the way, if there is another point N(2.2, sin(2.2)), will M and N  
> conflict (overlap) each other?

I don't see how that could be avoided. (Last color wins.) We don't  
have 3d glasses for our screens yet. Transparenct colors are  
available, but you don't seem to be ready for that yet.

>
> Cheers
> Pei
>
>
>
> On Wed, Jul 13, 2011 at 4:49 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Jul 13, 2011, at 7:42 PM, JIA Pei wrote:
>
>
>
>
> Hi, Thanks David Winsemius:
>
>
> "mtext" works !! However, in R plot, "mtext" will automatically  
> overlap/overwrite the existing coordinates, which makes the  
> coordinates a messy.
> Refer to http://www.visionopen.com/Rplot.png , which is produced by  
> only 3 lines.
>
> dev.new(width = 640, height = 480)
> plot(sin, -pi, 2*pi)
> mtext(text="2.1000", side = 1, line = 1,  at = 2.1)
>
> In order to avoid the coordinates overlap, can I change the position  
> of "2.1000" from outside the box to inside the box? If possible, how  
> to?
> I tried "outer = FALSE," nothing special happened ever !!
>
> You should use text() rather than mtext() if you are going to plot  
> within the "user area".
>
>
>
>
> cheers
> Pei
>
>
>
> On Wed, Jul 13, 2011 at 1:41 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Jul 13, 2011, at 1:22 PM, JIA Pei wrote:
>
> Hi, all:
>
> I used two lines of very simple code to draw a sin curve.
>
> dev.new(width = 640, height = 480)
> plot(sin, -pi, 2*pi)
>
> First look at:
>
> ?mtext   # then try
> mtext(text="2.5000", side = 1, line = 1,  at = 2.5)
>
>
>
> Now, I added a specific line (red line in the picture at
> http://www.visionopen.com/Rplot.png) by using abline.
> However, I still love to add the X-coordinate "2.50000" outside the
> rectangle box. How to do it in R?
> Right now, I'm using Windows Paint to add the characters "2.50000"  
> up to the
> plot drawn by R.
>
>
-- 

David Winsemius, MD
West Hartford, CT

______________________________________________
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.



More information about the R-help mailing list