batholdy at googlemail.com
2009-Mar-05 00:06 UTC
[R] text at the upper left corner outside of the plot region
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!
Jim Lemon
2009-Mar-05 10:32 UTC
[R] text at the upper left corner outside of the plot region
batholdy at googlemail.com wrote:> 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. >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
Eik Vettorazzi
2009-Mar-05 11:15 UTC
[R] text at the upper left corner outside of the plot region
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:> 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! > > ______________________________________________ > 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.-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790
Greg Snow
2009-Mar-05 17:07 UTC
[R] text at the upper left corner outside of the plot region
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, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of batholdy at googlemail.com > Sent: Wednesday, March 04, 2009 5:06 PM > To: r-help at r-project.org > Subject: [R] text at the upper left corner outside of the plot region > > 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! > > ______________________________________________ > 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.