Skip to content

text at the upper left corner outside of the plot region

4 messages · Martin Batholdy, Jim Lemon, Eik Vettorazzi +1 more

#
Hi,

is there a way to place text at the upper left corner (or another  
corner) of the plot?

I want to place it really at the upper left corner of the whole plot  
(the file I get),
not at the upper left corner of the plot-region.



I tried text() and mtext(), and corner.label() of the plotrix package  
but it didn't work out.


thanks!
#
batholdy at googlemail.com wrote:
Hi batholdy,
I suppose we could rewrite corner.label like this:

corner.label<-function(label=NULL,x=-1,y=1,xoffset=NA,yoffset=NA,
 space=c("plot","figure"),...) {

 if(is.na(xoffset)) xoffset<-strwidth("m")/2
 if(is.na(yoffset)) yoffset<-strheight("m")/2
 par.usr<-par("usr")
 xpos<-par.usr[(3+x)/2]
 ypos<-par.usr[(3+y)/2+2]
 if(match(space[1],"figure",0)) {
  par.pin<-par("pin")
  xplotrange<-par.usr[2]-par.usr[1]
  yplotrange<-par.usr[4]-par.usr[3]
  par.mai<-par("mai")
  xmar<-xplotrange*par.mai[3+x]/par.pin[1]
  ymar<-yplotrange*par.mai[2+y]/par.pin[2]
  cat(xmar,ymar,"\n")
  xpos<-xpos+x*xmar
  ypos<-ypos+y*ymar
 }
 if(!is.null(label)) {
  if(match(space[1],"figure",0)) par(xpd=TRUE)
  text(xpos-x*xoffset,ypos-y*yoffset,label,adj=c((1+x)/2,(1+y)/2))
  if(match(space[1],"figure",0)) par(xpd=FALSE)
 }
 return(list(x=xpos,y=ypos))
}

The default behavior is to put the label just inside one corner of the 
plot. If you set "space" to "figure", the label will appear just inside 
one corner of the figure region. Owzat?

Jim
#
is this something that helps?
plot(1,2)
mtext("test low right",side=1,outer=T,adj=1,line=-1)
mtext("test low left",side=1,outer=T,adj=0,line=-1)
mtext("test upper right",side=3,outer=T,adj=1,line=-1)
mtext("test upper left",side=3,outer=T,adj=0,line=-1)

hth


batholdy at googlemail.com schrieb:

  
    
#
In addition to the other responses that you have received, you can use the grconvertX and grconvertY functions to convert between the different coordinate systems, the upper left corner will be 0,1 in ndc (whole device/page), nfc (figure region), npc (plot region), or nic (inside the outer margins) coordinates, convert this to user coordinates and use the text function.  You may need to turn off clipping, see the xpd entry under ?par.

Hope this helps,