[R] Coordinate or top left corner + offset

Pascal A. Niklaus Pascal.Niklaus at ieu.uzh.ch
Mon Feb 9 17:26:40 CET 2015


Dear all,

I am struggling to add annotations to panels of a series of plots 
arranged on a page.

Basically, I'd like to add letters enumerating the panels 
("a","b","c",...), at a fixed distance from the top left corner of the 
plot's "box".

I succeeded partly with "mtext" (see below), but the "at" option is in 
user coordinates, which makes is difficult to specify a given offset 
from the corner (e.g. 1cm from top and left).

I tried grid's "npc" but these coordinates refer to the entire plot 
instead of the current inner plotting region.

Phrased differently, I'd like to place text (and ideally also be able to 
plot, e.g. a white disc to cover background items) at position 
(top-1cm,left+1cm)

Here is a minimum working example illustrating what I try to achieve:


pdf("example.pdf",width=15,height=15)

m <- rbind( c(0.1,0.9,0.1,0.6),
             c(0.1,0.9,0.6,0.9)
      );

split.screen(m)

screen(1);
par(mar=c(0,0,0,0));
plot(rnorm(10),rnorm(10),xlim=c(-5,5),xaxt="n",yaxt="n");
mtext(quote(bold(a)),side=3,line=-2.5,at=-5,cex=2.5)

screen(2);
par(mar=c(0,0,0,0));
plot(rnorm(10),rnorm(10),xlim=c(-3,3),xaxt="n",yaxt="n");
mtext(quote(bold(a)),side=3,line=-2.5,at=-3,cex=2.5)


close.screen(all.screens=TRUE)

dev.off()


Thanks for your help

Pascal Niklaus



More information about the R-help mailing list