bolker@zoo.ufl.edu
2001-Jan-15 16:05 UTC
[Rd] legend() patch never seems to have made it in
Perhaps I should have submitted this as a bug so that it would be officially tracked. It's not a big deal, but here it is again (I can't remember which version this patch is against, but I don't think legend() has changed since then ...) Basically, the problem is that if you want to have "opaque" points that overlay lines (rather than using type="b" and having the lines leave a little bit of space around the points), you can use pch=21,bg=par("bg"), but this is hard to replicate in legend(). For example: x <- 1:10 y <- runif(10) plot(x,y,type="l",ylim=c(0,1.2)) points(x,y,pch=21,bg="white") legend(6,1.2,"foo",pch=21,pt.bg="white",lty=1) Here's the patch, which reverses the order of line- and point-drawing so that points come later and can overwrite the lines: *** new-legend.R Thu Oct 19 16:25:36 2000 --- R-devel/src/library/base/R/legend.R Wed Sep 6 04:11:16 2000 *************** *** 141,171 **** } if(has.pch || do.lines) col <- rep(col,length.out=n.leg) - - if (do.lines) { #- draw lines --------------------- - seg.len <- 2 # length of drawn segment, in xchar units - ok.l <- if(missing(lty)) { lty <- 1; TRUE } else lty > 0 - if(missing(lwd)) lwd <- par("lwd") - lty <- rep(lty, length.out = n.leg) - lwd <- rep(lwd, length.out = n.leg) - if(trace) - catn(" segments2(",xt[ok.l] + x.off*xchar ,",", yt[ok.l], - ", dx=",seg.len*xchar,", dy=0, ...)", sep="") - segments2(xt[ok.l] + x.off*xchar, yt[ok.l], dx= seg.len*xchar, dy=0, - lty = lty[ok.l], lwd = lwd[ok.l], col = col[ok.l]) - # if (!merge) - xt <- xt + (seg.len+x.off) * xchar - } if (has.pch) { #- draw points ------------------- pch <- rep(pch, length.out=n.leg) pt.bg <- rep(pt.bg, length.out=n.leg) ok <- is.character(pch) | pch >= 0 ! x1 <- (if(merge) xt-(seg.len/2)*xchar else xt)[ok] y1 <- yt[ok] if(trace) catn(" points2(", x1,",", y1,", pch=", pch[ok],"...)") points2(x1, y1, pch=pch[ok], col=col[ok], cex=cex, bg = pt.bg[ok]) if (!merge) xt <- xt + dx.pch } xt <- xt + x.intersp * xchar --- 141,169 ---- } if(has.pch || do.lines) col <- rep(col,length.out=n.leg) if (has.pch) { #- draw points ------------------- pch <- rep(pch, length.out=n.leg) pt.bg <- rep(pt.bg, length.out=n.leg) ok <- is.character(pch) | pch >= 0 ! x1 <- (if(merge) xt + 0.2*xchar else xt)[ok] y1 <- yt[ok] if(trace) catn(" points2(", x1,",", y1,", pch=", pch[ok],"...)") points2(x1, y1, pch=pch[ok], col=col[ok], cex=cex, bg = pt.bg[ok]) if (!merge) xt <- xt + dx.pch + } + if (do.lines) { #- draw lines --------------------- + ok.l <- if(missing(lty)) { lty <- 1; TRUE } else lty > 0 + if(missing(lwd)) lwd <- par("lwd") + lty <- rep(lty, length.out = n.leg) + lwd <- rep(lwd, length.out = n.leg) + if(trace) + catn(" segments2(",xt[ok.l] + x.off*xchar ,",", yt[ok.l], + ", dx=",2*xchar,", dy=0, ...)", sep="") + segments2(xt[ok.l] + x.off*xchar, yt[ok.l], dx= 2*xchar, dy=0, + lty = lty[ok.l], lwd = lwd[ok.l], col = col[ok.l]) + ## if (!merge) + xt <- xt + (2+x.off) * xchar } xt <- xt + x.intersp * xchar -- 318 Carr Hall bolker@zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._