[Rd] mva:princomp.default not set correctly (PR#3168)

irwin at imcs.rutgers.edu irwin at imcs.rutgers.edu
Mon Jun 2 18:17:24 MEST 2003


Full_Name: Andrew Irwin
Version: 1.7.0
OS: Win98
Submission from: (NULL) (165.230.175.97)



It is impossible to set both xlim and ylim in princomp or princomp.default.

For example
  data(USArrests)
  biplot(princomp(USArrests))
works fine, but
  biplot(princomp(USArrests), xlim=c(-0.4, 0.4), ylim=c(-0.5,0.4) )
does not do what I would expect -- the ylim gets ignored.

The offending bit of code from mva:princomp.default seems to be

    if (missing(xlim) && missing(ylim)) 
        xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
    else if (missing(xlim)) 
        xlim <- rangx1
    else ylim <- rangx2


This if .. else if .. else clause is not written the way I think it should be
written.  The else clause should only be executed if ylim is missing, but it
will be executed if xlim and ylim are both present.

Suggested rewrite:

    if (missing(xlim) && missing(ylim)) 
        xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
    else if (missing(xlim)) 
        xlim <- rangx1
    else if (missing(ylim))
        ylim <- rangx2

ifelse clause might be better, but less readable.

Cheers,

Andrew



More information about the R-devel mailing list