putting text in the corner

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

putting text in the corner

Thomas Steiner
I want to write some text in a corner of my plot.
Is it possible to get the xlim and ylim of an open window?
Or is there anything similar like
legend(x="bottomright", inset=0.01,legend=...)
for
text(x=1,y=2, "test")

Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Marc Schwartz (via MN)
On Thu, 2006-02-09 at 17:18 +0100, Thomas Steiner wrote:
> I want to write some text in a corner of my plot.
> Is it possible to get the xlim and ylim of an open window?
> Or is there anything similar like
> legend(x="bottomright", inset=0.01,legend=...)
> for
> text(x=1,y=2, "test")
>
> Thomas


Try this:

 plot(1:10)

 # par("usr") defines the x/y coordinates of the plot region
 usr <- par("usr")

 # Upper Left Hand Corner
 text(usr[1], usr[4], "test", adj = c(0, 1))

 # Lower Left Hand Corner
 text(usr[1], usr[3], "test", adj = c(0, 0))

 # Lower Right Hand Corner
 text(usr[2], usr[3], "test", adj = c(1, 0))

 # Upper Right Hand Corner
 text(usr[2], usr[4], "test", adj = c(1, 1))



See ?par and ?text for more information including the 'adj' argument to
text().

HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Fernando Mayer
In reply to this post by Thomas Steiner
You can get the x and y position of any place of an open graphic device
with the mouse cursor, using the function locator(), and even assing
this values to an object, as in:

xy<-locator()

You will have a list with x and y positions. Then you can use:

text(xy$x,xy$y,...)

See ?locator.

HTH,
Fernando Mayer.

Thomas Steiner escreveu:

>I want to write some text in a corner of my plot.
>Is it possible to get the xlim and ylim of an open window?
>Or is there anything similar like
>legend(x="bottomright", inset=0.01,legend=...)
>for
>text(x=1,y=2, "test")
>
>Thomas
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Duncan Murdoch
In reply to this post by Thomas Steiner
On 2/9/2006 11:18 AM, Thomas Steiner wrote:
> I want to write some text in a corner of my plot.
> Is it possible to get the xlim and ylim of an open window?
> Or is there anything similar like
> legend(x="bottomright", inset=0.01,legend=...)
> for
> text(x=1,y=2, "test")

par("usr")

gives you the limits.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Brian Ripley
In reply to this post by Thomas Steiner
?par, look at "usr"  (which is how legend does it)

On Thu, 9 Feb 2006, Thomas Steiner wrote:

> I want to write some text in a corner of my plot.
> Is it possible to get the xlim and ylim of an open window?
> Or is there anything similar like
> legend(x="bottomright", inset=0.01,legend=...)
> for
> text(x=1,y=2, "test")

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Gregory Snow
In reply to this post by Thomas Steiner

par('usr') will give you the coordinates of the corners of the current plot.  

If you want to go a little beyond this (more like your legend example) by specifying that you want your text to be some distance from the bottom and left of the plot and have the distance not affected by the scale of the data then you might want to look at the cnvrt.coords function in the TeachingDemos package.

-----Original Message-----
From: [hidden email] on behalf of Thomas Steiner
Sent: Thu 2/9/2006 9:18 AM
To: [hidden email]
Subject: [R] putting text in the corner
 
I want to write some text in a corner of my plot.
Is it possible to get the xlim and ylim of an open window?
Or is there anything similar like
legend(x="bottomright", inset=0.01,legend=...)
for
text(x=1,y=2, "test")

Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Kjetil Halvorsen
In reply to this post by Fernando Mayer
Fernando Mayer wrote:
> You can get the x and y position of any place of an open graphic device
> with the mouse cursor, using the function locator(), and even assing
> this values to an object, as in:
>
> xy<-locator()
>
> You will have a list with x and y positions. Then you can use:
>
> text(xy$x,xy$y,...)

or even
    text(locator(), "test", ...)

Kjetil


>
> See ?locator.
>
> HTH,
> Fernando Mayer.
>
> Thomas Steiner escreveu:
>
>> I want to write some text in a corner of my plot.
>> Is it possible to get the xlim and ylim of an open window?
>> Or is there anything similar like
>> legend(x="bottomright", inset=0.01,legend=...)
>> for
>> text(x=1,y=2, "test")
>>
>> Thomas
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>>  
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: putting text in the corner

Thomas Steiner
In reply to this post by Duncan Murdoch
Thank you all.

> par("usr")

is the perfect solution.

It *is* in the help files, but was quite hard to find.

Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html