[R] Text

Patrick Connolly p_connolly at slingshot.co.nz
Mon Sep 1 22:09:01 CEST 2008


On Mon, 01-Sep-2008 at 07:32PM +0200, Dani Valverde wrote:

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

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

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}          		 Great minds discuss ideas    
 _( Y )_  	  	        Middle minds discuss events 
(:_~*~_:) 	       		 Small minds discuss people  
 (_)-(_)  	                           ..... Anon
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.



More information about the R-help mailing list