Skip to content
Prev 313962 / 398506 Next

triax.plot: control legend position and size of point labels

On 12/19/2012 11:18 PM, maxbre wrote:
Hi maxbre,
For the legend, I would suggest calling triax.plot  with legend=FALSE 
and then adding the legend where you want it. To change the size of the 
point labels you would have to modify the function. Here is the 
triax.points function with the necessary modification:

triax.points<-function(x,show.legend=FALSE,label.points=FALSE,
  point.labels=NULL,col.symbols=par("fg"),pch=par("pch"),
  bg.symbols=par("bg"),cc.axes=FALSE,...) {

  if(dev.cur() == 1)
   stop("Cannot add points unless the triax.frame has been drawn")
  if(missing(x))
   stop("Usage: triax.points(x,...)\n\twhere x is a 3 column array of 
proportions or percentages")
  if(!is.matrix(x) && !is.data.frame(x))
   stop("x must be a matrix or data frame with at least 3 columns and 
one row.")
  if(any(x > 1) || any(x < 0)) {
   if(any(x < 0))
    stop("All proportions must be between zero and one.")
   if(any(x > 100))
    stop("All percentages must be between zero and 100.")
   # convert percentages to proportions
   x<-x/100
  }
  if(any(abs(rowSums(x)-1) > 0.01))
   warning("At least one set of proportions does not equal one.")
  sin60<-sin(pi/3)
  if(cc.axes) {
   ypos<-x[,3]*sin60
   xpos<-x[,1]+x[,3]*0.5
  }
  else {
   ypos<-x[,3]*sin60
   xpos<-1-(x[,1]+x[,3]*0.5)
  }
  nobs<-dim(x)[1]
  points(x=xpos,y=ypos,pch=pch,col=col.symbols,bg=bg.symbols,type="p",...)
  if(is.null(point.labels)) point.labels<-rownames(x)
  if(label.points) 
thigmophobe.labels(xpos,ypos,point.labels,cex=par("cex.axis"))
  if(show.legend) {
   legend(0.2,0.7,legend=point.labels,pch=pch,col=col.symbols,
    xjust=1,yjust=0)
  }
  invisible(list(x=xpos,y=ypos))
}

Note that some lines above may have been broken by the email client. If 
so, stitch them back together with a text editor before trying to 
"source" the file. I will probably add something like this to triax.plot 
in the next version of plotrix.

Jim