From maechler at stat.math.ethz.ch  Fri Aug 28 14:35:27 2009
From: maechler at stat.math.ethz.ch (maechler at stat.math.ethz.ch)
Date: Fri, 28 Aug 2009 14:35:27 +0200 (CEST)
Subject: [Rd] Wishlist: specify the border color of boxes in legend()
	(PR#13913)
Message-ID: <20090828123527.5A5502832005@mail.pubhealth.ku.dk>


>>>>> "FS" == Frederic Schutz <Frederic.Schutz at isb-sib.ch>
>>>>>     on Thu, 27 Aug 2009 13:25:16 +0200 (CEST) writes:

    FS> I could not find a way to specify the border color of the boxes drawn in
    FS> a legend, so that the legend can match exactly the colors of the actual
    FS> plot (e.g. in the case of two superimposed histograms which have
    FS> different shading and different borders).

    FS> Indeed, the legend function seems to hard code the color "black" for the
    FS> borders in this call:

    FS> rect2(left = xt, top = yt + ybox/2, dx = xbox, dy = ybox,
    FS> col = fill, density = density, angle = angle,
    FS> border = "black")

    FS> I worked around this by adding a "border" argument to the function
    FS> (which defaults to "black"), and changing the call above. It works for
    FS> me; I have looked quickly at the rest of the function to see if there
    FS> would be a side effect and did not see any (but I haven't checked
    FS> carefully).

    FS> This could be a useful improvement of the legend() function; in case the
    FS> change described above looks usable, I attach two simple diff files (for
    FS> the function itself and the manual page).

    FS> Cheers,
    FS> Fr?d?ric

Thank you, Fr?d?ric,
indeed, the changes are so minimal that I will apply the two
patches and they should be in "R-devel" (for R 2.10.0) soon.

Best regards,
Martin Maechler, ETH Zurich


    FS> --------------040007030503070307040509
    FS> Content-Type: text/x-patch;
    FS> name="legend.R.diff"
    FS> Content-Transfer-Encoding: 7bit
    FS> Content-Disposition: inline;
    FS> filename="legend.R.diff"

    FS> --- legend.R~	2009-03-20 00:05:18.000000000 +0100
    FS> +++ legend.R	2009-08-27 11:52:02.000000000 +0200
    FS> @@ -15,8 +15,8 @@
    FS> #  http://www.r-project.org/Licenses/
 
    FS> legend <-
    FS> -function(x, y = NULL, legend, fill=NULL, col = par("col"), lty, lwd, pch,
    FS> -	 angle = 45, density = NULL, bty = "o", bg = par("bg"),
    FS> +function(x, y = NULL, legend, fill=NULL, col = par("col"), border="black",
    FS> +         lty, lwd, pch, angle = 45, density = NULL, bty = "o", bg = par("bg"),
    FS> box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"),
    FS> pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,
    FS> xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1, adj = c(0, 0.5),
    FS> @@ -217,7 +217,7 @@
    FS> fill <- rep(fill, length.out = n.leg)
    FS> rect2(left = xt, top=yt+ybox/2, dx = xbox, dy = ybox,
    FS> col = fill,
    FS> -		  density = density, angle = angle, border = "black")
    FS> +		  density = density, angle = angle, border = border)
    FS> }
    FS> xt <- xt + dx.fill
    FS> }

    FS> --------------040007030503070307040509
    FS> Content-Type: text/x-patch;
    FS> name="legend.Rd.diff"
    FS> Content-Transfer-Encoding: 7bit
    FS> Content-Disposition: inline;
    FS> filename="legend.Rd.diff"

    FS> --- legend.Rd~	2009-03-20 00:05:18.000000000 +0100
    FS> +++ legend.Rd	2009-08-27 11:57:28.000000000 +0200
    FS> @@ -8,7 +8,7 @@
    FS> \title{Add Legends to Plots}
    FS> \usage{
    FS> legend(x, y = NULL, legend, fill = NULL, col = par("col"),
    FS> -       lty, lwd, pch,
    FS> +       border="black", lty, lwd, pch,
    FS> angle = 45, density = NULL, bty = "o", bg = par("bg"),
    FS> box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"),
    FS> pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,
    FS> @@ -34,6 +34,8 @@
    FS> with the specified colors (or shaded in the specified colors)
    FS> to appear beside the legend text.}
    FS> \item{col}{the color of points or lines appearing in the legend.}
    FS> +  \item{border}{the border color for the boxes (used only if
    FS> +    \code{fill} is specified).}
    FS> \item{lty, lwd}{the line types and widths for lines appearing in the
    FS> legend.  One of these two \emph{must} be specified for line drawing.}
    FS> \item{pch}{the plotting symbols appearing in the legend, either as

    FS> --------------040007030503070307040509--

    FS> ______________________________________________
    FS> R-devel at r-project.org mailing list
    FS> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Wishlist: specify the border color of boxes in legend() (PR#13913)
maechler at stat.math.ethz.ch