[Rd] legend's arguments "angle" and "density"

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Aug 20 19:44:40 CEST 2004


Martin Maechler wrote:

>>>>>>"UweL" == Uwe Ligges <ligges at statistik.uni-dortmund.de>
>>>>>>    on Fri, 20 Aug 2004 17:01:13 +0200 writes:
> 
> 
>     UweL> Paul Murrell wrote [on 2002-03-14 with Subject: "filled bars with 
>     UweL> patterns" in reply to Arne Mueller]
> 
>     >> Hi
>     >> 
>     >> <snip>
>     >> 
>     >>> I'd also like to have the filled boxes in the legend to be striped. The
>     >>> legend function has a 'density' attribute, but unfortunately this does't
>     >>> seem to do anything
>     >>> 
>     >>> following the above example
>     >>> 
>     >>> legend(3.4, 5, c('Axx','Bxx','Cxx','Dxx'), fill = c('red', 'blue',
>     >>> 'green', 'orange'))
>     >>> 
>     >>> is the same as
>     >>> 
>     >>> legend(3.4, 5, c('Axx','Bxx','Cxx','Dxx'), density=10, fill = c('red',
>     >>> 'blue', 'green', 'orange'),
>     >>> density=c(10,-1,20, 200))
>     >> 
>     >> 
>     >> 
>     >> This appears to be a bug.  Can you file a bug report for this please?
> 
>     UweL> [SNIP; I cannot find any related bug report in the repository]
> 
> 
>     UweL> I'm just reviewing bug reports and other stuff re. legend() and found 
>     UweL> this old message in one of my Next-Week-To-Do-folders.
> 
>     UweL> Well, the point mentioned above is not really a bug, because one has to 
>     UweL> specify BOTH arguments, angle AND density in legend(). Is there any 
>     UweL> point not to make angle = 45 the default, as it already is for polygon() 
>     UweL> and rect()?
> 
> This seems like a good idea,
> but we'll wait for your many other patches to legend.R and
> legend.Rd   :-)

Just three rather than many issues I'm trying to address, the third one 
is just closing a bug report. ;-)
Here the two suggested patches in merged form.

Uwe


--- y:\recent\R\src\library\graphics\R\legend.R
+++ legend.R    2004-08-20 19:36:26.000000000 +0200
@@ -1,7 +1,7 @@
  legend <-
  function(x, y = NULL, legend, fill=NULL, col = "black", lty, lwd, pch,
-     angle = NULL, density = NULL, bty = "o",
-     bg = par("bg"), pt.bg = NA, cex = 1, pt.cex = cex,
+     angle = 45, density = NULL, bty = "o", bg = par("bg"),
+     pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = par("lwd"),
       xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1, adj = c(0, 0.5),
       text.width = NULL, text.col = par("col"),
           merge = do.lines && has.pch, trace = FALSE,
@@ -178,8 +178,8 @@
      if(trace)
          catn("  points2(", x1,",", y1,", pch=", pch[ok],", ...)")
      if(plot)
-        points2(x1, y1,
-                    pch = pch[ok], col= col[ok], cex= pt.cex[ok], bg= 
pt.bg[ok])
+        points2(x1, y1, pch = pch[ok], col = col[ok], cex = pt.cex[ok],
+                bg = pt.bg[ok], lwd = pt.lwd)
      if (!merge) xt <- xt + dx.pch
      }






--- y:\recent\R\src\library\graphics\man\legend.Rd
+++ legend.Rd   2004-08-20 19:36:16.000000000 +0200
@@ -3,9 +3,9 @@
  \title{Add Legends to Plots}
  \usage{
  legend(x, y = NULL, legend, fill = NULL, col = "black", lty, lwd, pch,
-       angle = NULL, density = NULL, bty = "o", bg = par("bg"),
-       pt.bg = NA, cex = 1, pt.cex = cex, xjust = 0, yjust = 1,
-       x.intersp = 1, y.intersp = 1, adj = c(0, 0.5),
+       angle = 45, density = NULL, bty = "o", bg = par("bg"),
+       pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = par("lwd"), xjust = 0,
+       yjust = 1, x.intersp = 1, y.intersp = 1, adj = c(0, 0.5),
         text.width = NULL, text.col = par("col"),
         merge = do.lines && has.pch, trace = FALSE,
         plot = TRUE, ncol = 1, horiz = FALSE)
@@ -43,6 +43,7 @@
    \item{cex}{character expansion factor \bold{relative} to current
      \code{par("cex")}.}
    \item{pt.cex}{expansion factor(s) for the points.}
+  \item{pt.lwd}{line width for the points.}
    \item{xjust}{how the legend is to be justified relative to the legend
      x location.  A value of 0 means left justified, 0.5 means centered
      and 1 means right justified.}



More information about the R-devel mailing list