Re: [Rd] legend lwd - feature request (PR#7023)

From: <ligges_at_statistik.uni-dortmund.de>
Date: Fri 20 Aug 2004 - 23:17:11 EST


Lfo@psykiatri.aaa.dk wrote:

> (R1.9.1 Windows)
>
> In legend( ) lwd have no effect on points - contrary to the behaviour
> in e.g. plot( ) and points( ). It would be nice to have an option pt.lwd
> affecting the line width of legend points (like pt.cex changes the
> magnification).
>
>
> An example (note the difference in line width between points in the
> plot and the legend):
> x <- 1:10 ; y <- rnorm(10,10,5) ; y2 <- rnorm(10,8,4)
> plot(x,y,bty="l",lwd=3,type="o",col=2,ylim=c(min(y,y2),max(y,y2)),cex=1.5)
> points(x,y2,lwd=3,lty=8,col=4,type="o",pch=2,cex=1.5)
> legend(10,max(y,y2),legend=c("Method 1","Method
> 2"),col=c(2,4),lty=c(1,8),pch=c(1,2),
> xjust=1,yjust=1,pt.cex=1.5,lwd=3)
>
> Workaround (thanks to Peter Dalgaard):
> x <- 1:10 ; y <- rnorm(10,10,5) ; y2 <- rnorm(10,8,4)
> plot(x,y,bty="l",lwd=3,type="o",col=2,ylim=c(min(y,y2),max(y,y2)),cex=1.5)
> points(x,y2,lwd=3,lty=8,col=4,type="o",pch=2,cex=1.5)
> legend(10,max(y,y2),legend=c("Method 1","Method
> 2"),col=c(0,0),lty=c(1,8),pch=c(1,2),
> xjust=1,yjust=1,pt.cex=1.5,lwd=0,text.col=0)
> pp <- par(lwd=3)
> legend(10,max(y,y2),legend=c("Method 1","Method 2"),
> col=c(2,4),lty=c(1,8),pch=c(1,2),
> xjust=1,yjust=1,pt.cex=1.5,lwd=3,bty="n")
> par(pp)

The quick patch at the end of this message will add an argument pt.lwd to legend(). Note that this argument only accepts one value for all point, because vectorized widths are not supported by points() and friends.

There is another point to consider for the long term: In order to restrict the possibly huge amount of possible values for legend() and make it legend() more flexible (I know, it already is very flexible), one might want to invent new arguments like point.args, line.args, text.args that accept lists of arguments to be passed to the corresponding underlying functions. However, that would require a redesign of legend() - and would certainly break some code ...

Uwe Ligges

Patch, diff'ed against r-devel (rev. 30796):


R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Aug 20 23:26:06 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:07 EST