[R] lines(..., lwd=3) inaccuracy

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 16 21:43:06 CEST 2011


On Thu, 16 Jun 2011, Sarah Goslee wrote:

> Hi Frank,
>
> It's not inaccuracy, exactly, and it's intentional.
>
> The default behavior is to use a round endcap on a line, and with such
> a large linewidth that endcap is arcing below and above the starting
> points.
>
> This being R, there's a par for that: putting lend=1 in your lines()
> statements will give you the result you're looking for.

And for those who can't remember which is which, lend = "butt".

>
> Sarah
>
> On Thu, Jun 16, 2011 at 3:03 PM, Frank Harrell <f.harrell at vanderbilt.edu> wrote:
>> Using a line width > 1 results in not only a thicker line but also some fuzz
>> in the other direction, as shown in this example program.  You will see that
>> the thick vertical black lines extend below the gray scale horizontal lines.
>> Does anyone know whether this is intended or is it a bug?  The application
>> is for displaying a correlation matrix (here just some random U(0,1)s).
>> Thanks -Frank
>>
>>
>> par(mar=c(1,2,0,0), xpd=NA)
>> set.seed(1)
>> r <- matrix(runif(16), nrow=4, dimnames=list(NULL, paste('x', 1:4, sep='')))
>> p <- nrow(r)
>> v <- colnames(r)
>> plot(c(-.35,p+.5),c(.5,p+.25), type='n', axes=FALSE,
>>     xlab='',ylab='')
>> text(rep(.5,p), 1:p, v, adj=1)
>> maxabsr <- max(abs(r[row(r) != col(r)]))
>> for(i in 1:p) {
>>  for(j in 1:p) {
>>    if(i >= j) next
>>    lines(c(i,i),c(j,j+r[i,j]/maxabsr/2), lwd=3)
>>    lines(c(i-.2,i+.2),c(j,j), col=gray(.7))
>>  }
>>  text(i, i, v[i], srt=-45, adj=0)
>> }
>>
>>
>
>
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list