Skip to content

Text

6 messages · Peter Dalgaard, Dani Valverde, Patrick Connolly +2 more

#
Hello,
I would like to place some text that should appear in the same position 
of the graphic device, preferably outside the plotting area, regardless 
the x and y axes limits. How can I do this?
Best,

Dani
#
Dani Valverde wrote:
I think you can use title() with an adj= argument.

Otherwise, try mtext(), using par("usr") and par("pin") to calculate the
at= argument.

  
    
#
I've thought about it, but the position should be always the same, 
locator() should return me the same value.

Daniel Valverde Saub?

Grup de Biologia Molecular de Llevats
Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona
Edifici V, Campus UAB
08193 Cerdanyola del Vall?s- SPAIN

Centro de Investigaci?n Biom?dica en Red
en Bioingenier?a, Biomateriales y
Nanomedicina (CIBER-BBN)

Grup d'Aplicacions Biom?diques de la RMN
Facultat de Bioci?ncies
Universitat Aut?noma de Barcelona
Edifici Cs, Campus UAB
08193 Cerdanyola del Vall?s- SPAIN
+34 93 5814126



En/na Peter Dalgaard ha escrit:
#
On Mon, 01-Sep-2008 at 07:32PM +0200, Dani Valverde wrote:

            
Here's a function I wrote for this type of job many years ago.  The xp
and yp paramaters are very similar to ncp units in grid.


add.text <-
function(xp = 0.5, yp = 0.5, tex = NULL, ygap = 0.05, cex = 0.8, adj = 0,
         adj.y = 0, font = 1, srt = 0, ...)
{
    uu <- par()$usr
    xd <- diff(uu[1:2])
    yd <- diff(uu[3:4])
    yp <- yp - (seq(along = tex) - 1) * ygap
    if(length(xp) == 1)
       xp <- rep(xp, length(tex))
    if(length(cex) == 1)
       cex <- rep(cex, length(xp))
    if(length(adj) == 1)
       adj <- rep(adj, length(xp))
    if(length(font) == 1)
       font <- rep(font, length(xp))
    xh <- uu[1] + xd * xp
    yh <- uu[3] + yd * yp
    for(i in 1:length(tex)) {
       text(xh[i], yh[i], tex[i], adj = c(adj[i], adj.y), cex = cex[i],
            font = font[i], srt = srt, ...)
    }
}

HTH
#
In recent versions of R there are the functions grconvertX and grconvertY that will convert between the different coordiate systems.  You can use them to convert from the device or ndc systems to user coordinates, then place the text using the text function.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111
#
Dani,
You can put text on your graphs using the locator function. Here is an example

hist(rnorm(1000,0,1) #plots a histogram for you
xy.cord<-locator(1) #Once you give this click on the graph to get the coordinates
text(xy.cord, "Text you want to write")

Hope this helps.
Cheers../Murli




-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Greg Snow
Sent: Tuesday, September 02, 2008 1:38 PM
To: Dani Valverde; R Help
Subject: Re: [R] Text

In recent versions of R there are the functions grconvertX and grconvertY that will convert between the different coordiate systems.  You can use them to convert from the device or ndc systems to user coordinates, then place the text using the text function.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111
______________________________________________
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.