Hi, I'm trying to construct a legend which has four lines of text and associated symbols. The first two symbols need to be normal lines which vary only in colour. The second two symbols should have filled boxes. How do I suppress the fill boxes in the first two lines? J.
I think this does what you want... Jerome plot(0,0) legend(0,0,c("blah","blahblah","blahblahblah","blah..."), pch=c(21,21,22,22), col=c("green","red","blue","blue"), pt.bg=c("white","white","yellow","orange"),cex=2) On Sunday 23 February 2003 17:29, Jeremy Z Butler wrote:> Content-Length: 419 > Status: R > X-Status: N > > > > > > > Hi, > I'm trying to construct a legend which has four lines of text and > associated symbols. The first two symbols need to be normal lines which > vary only in colour. The second two symbols should have filled boxes. How > do I suppress the fill boxes in the first two lines? > J. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help-- Jerome Asselin (J?r?me) Statistical Analyst British Columbia Centre for Excellence in HIV/AIDS St. Paul's Hospital 608 - 1081 Burrard Street Vancouver, British Columbia CANADA V6Z 1Y6 Email: jerome at hivnet.ubc.ca Phone: 604 806-9112 Fax: 604 806-9044
Jeremy Z. Butler wrote:> > Hi, > I'm trying to construct a legend which has four lines of text and > associated symbols. The first two symbols need to be normal lines which > vary only in colour. The second two symbols should have filled boxes. How > do I suppress the fill boxes in the first two lines? > J.As far as I can see, it would be really hard to suppress the fill boxes. However, it isn't too hard to overwrite the point/line indicators. First, do the legend like this: legendinfo<-legend(...,lty=1,col=c(...)) This will produce a legend with all different colored lines. Then call the function below like this: add.legend.bars(legendinfo,which=c(3,4),border="black",col=c(2,3)) The function below seems to work for a linear or log axis plot. Hope it helps. Jim add.legend.bars<-function(legend.info,which,border,col) { if(!missing(legend.info) && !missing(which) && !missing(border) && !missing(col)) { nelem<-length(legend.info$text$x) if(par("ylog")) barheight<-(10^legend.info$text$y[1]-10^legend.info$text$y[2])/2 else barheight<-(legend.info$text$y[1]-legend.info$text$y[2])/2 if(par("xlog")) barwidth<-(10^legend.info$text$x[1]-10^legend.info$rect$left)/2 else barwidth<-(legend.info$text$x[1]-legend.info$rect$left)/2 if(par("xlog")) xleft<-10^legend.info$rect$left+barwidth/2 else xleft<-legend.info$rect$left+barwidth/2 xright<-xleft+barwidth if(par("ylog")) ytop<-(10^legend.info$text$y+barheight/2)[which] else ytop<-(legend.info$text$y+barheight/2)[which] ybottom<-ytop-barheight rect(xleft,ybottom,xright,ytop,border=border,col=col) } else cat("Usage: add.legend.bars(legend.info,which,border,col)\n") } UTS CRICOS Provider Code: 00099F DISCLAIMER\ ==================================================== ... [[dropped]]