From maechler at stat.math.ethz.ch  Sat Feb  2 13:00:32 2008
From: maechler at stat.math.ethz.ch (maechler at stat.math.ethz.ch)
Date: Sat,  2 Feb 2008 13:00:32 +0100 (CET)
Subject: [Rd] bug using matplot (PR#10676)
Message-ID: <20080202120032.A4902283484B@mail.pubhealth.ku.dk>

>>>>> "GS" == Gavin Simpson <gavin.simpson at ucl.ac.uk>
>>>>>     on Fri, 01 Feb 2008 18:08:54 +0000 writes:

    GS> On Fri, 2008-02-01 at 16:20 +0100, cori at u707.jussieu.fr
    GS> wrote:
    >> Full_Name: Anne CORI Version: 2.6.1 OS: windows
    >> Submission from: (NULL) (134.157.220.19)
    >> 
    >> 
    >> let A be a mtrix with n lines and p columns, p>36 ;
    >> 
    >> matplot(A) will only draw the plot of the first 36
    >> columns of A.
    >> 
    >> This is due to a bug in the definition of pch in the
    >> function :
    >> 
    >> pch <- c(paste(c(1:9, 0)), letters)[1:k]

    GS> You need this here,

actually not (anymore; porbably it *was* needed in amuch older
version of R),
because of the later  rep(u, length.out=k) which also works when
u is longer than k

    GS> the issue is that the default is only length 36 and you
    GS> aren't warned if you have more variables than that *if*
    GS> you rely upon the default and don't specify pch in you
    GS> call to matplot.

    GS> This works fine for example:

    GS> dat <- matrix(rnorm(400), ncol = 40) 
    GS> matplot(dat, pch = c(paste(1:9, 0, letters, LETTERS)))

yes.

    >> should be replaced by
    >> 
    >> pch <- c(paste(c(1:9, 0)), letters)

    GS> That won't help.

well, it does help insofar as columns (>= 37) are then plotted
at all.

But you are right about this :

    GS>  The vector, pch, will get recycled so
    GS> you won't be able to tell the difference between vars
    GS> 1,2,3 etc and 37,38,39 etc. (See the series of
    GS> if(length(.....) < k) statements towards the end of the
    GS> function definition for matplot.

    GS> This is working as documented, although one might
    GS> consider it an infelicity in the implementation that it
    GS> doesn't warn you that k is > 36 and suggest you pass
    GS> your own set of plotting characters.

yes.

I do agree with Anne that there is a bug.
Following Gavin (and Anne, too),
I'm proposing to do the following :

1) recycle pch when it's too short;  this already happens for
  user specified pch, so should also happen for the default pch.

2) warn then the default pch is too short (and hence recycled by
   "1)"), I wouldn't add an explicit suggestion to use your own.

   My current working proposal would say

 >>   Warning message:
 >>   In matplot(1:100, m, type = "o") :
 >>     default 'pch' is smaller than number of columns and hence recycled

   and the useR  would understand that she can specify her
   own pch, right?


3) extend the default pch to include LETTERS, i.e., to  
   c(1:9,0, letters, LETTERS)

Thanks to Anne and Gavin for the report and analysis!

Martin



[Rd] bug using matplot (PR#10676)
maechler at stat.math.ethz.ch