[R] Error in 'legend' help?

Marc Schwartz MSchwartz at MedAnalytics.com
Thu Mar 25 14:33:50 CET 2004


On Thu, 2004-03-25 at 07:17, Rau, Roland wrote:
> Dear all,
> 
> maybe I have misunderstood something but to me it seems like a minor error
> in the help for
> ?legend
> for the argument 'bg'. There it says:
> 
>       bg: the background color for the legend box.  (Note that this is
>           only used if 'bty = "n"'.)
> 
> I think, however, that it should be changed to:
> 
>       bg: the background color for the legend box.  (Note that this is
>           only used if 'bty = "o"'.)
> 
> Here is some example code. And only in the upper panel we can see a legend
> with a blue background.
> 
> par(mfrow=c(2,1))
> plot(x=1:10, y=1:10)
> legend(x=5,y=5, legend="Legend-Text", bty="o", bg="blue")
> 
> plot(x=1:10, y=1:10)
> legend(x=5,y=5, legend="Legend-Text", bty="n", bg="blue")
> 
> My R version is:
> > version
>          _              
> platform i386-pc-mingw32
> arch     i386           
> os       mingw32        
> system   i386, mingw32  
> status                  
> major    1              
> minor    8.1            
> year     2003           
> month    11             
> day      21             
> language R       
> 
> Best,
> Roland


It is a typo. The relevant code in legend() is:

    if (plot && bty != "n") {
        if (trace) 
            catn("  rect2(", left, ",", top, ", w=", w, ", h=", 
                h, ", ...)", sep = "")
        rect2(left, top, dx = w, dy = h, col = bg, density = NULL)
    }


So the help _should_ read:

   bg: the background color for the legend box.  (Note that this is
          only used if 'bty != "n"'.)

HTH,

Marc Schwartz




More information about the R-help mailing list