Skip to content
Prev 154714 / 398503 Next

Text

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