Skip to content
Prev 383150 / 398502 Next

Label

Hi Val,
A good suggestion. The revised code is below and it will be in the
next version of plotrix.

barlabels<-function(xpos,ypos,labels=NULL,cex=1,prop=0.5,miny=0,offset=0,
 nobox=FALSE,...) {

 if(is.data.frame(ypos)) ypos<-as.matrix(ypos)
 if(is.null(labels)) labels<-ypos
 # usually don't want to display zero labels
 display<-ypos > miny
 if(is.matrix(ypos)) {
  # prop is within the scope of the current environment
  cumcenter<-function(x,pos) return(cumsum(x)-x*prop)
  stacked<-length(xpos) < length(ypos)
  if(stacked) {
   # replicate the x positions one by one, but the offsets group by group
   xpos<-rep(xpos,each=length(ypos)/length(xpos))+
    rep(c(-offset,offset),length(ypos)/(2*length(xpos)))
   ypos<-apply(ypos,2,cumcenter)
  }
  else ypos<-ypos*prop
 }
 else ypos<-ypos*prop
 # allow labels to extend beyond the plot area
 par(xpd=TRUE)
 if(nobox) text(xpos[display],ypos[display],labels[display],cex=cex,...)
 else boxed.labels(xpos[display],ypos[display],labels[display],cex=cex,...)
 par(xpd=FALSE)
}

Just set "nobox" to TRUE. You can add a "col=" argument at the end and
it will be passed to "text".

Jim
On Sat, Apr 4, 2020 at 5:20 AM Val <valkremk at gmail.com> wrote: