R: Draw lines for groups distinguished by a factor

multilines {ca} | R Documentation

## Draw lines for groups distinguished by a factor

### Description

This is a convenience function for drawing a set of lines distinguished by the levels of a factor. It can be used to make more attractive plots than available via `plot.mjca`.

### Usage

    multilines(XY, group=NULL, which=1:nf, sort=1, type='l', col=palette(), lwd=1, ...)

### Arguments

`XY` | A two-column data frame or matrix
`group` | A factor; a separate line is drawn for each level included in `which`
`which` | An integer vector used to select the factors for which lines are drawn. By default, all lines are drawn.
`sort` | Column of `XY` to sort upon before drawing the line for each group
`type` | Line type: `"l"` for line, `"b"` for line and points
`col` | A vector of colors to be used for the various lines, in the order of the levels in `group`; recycled as necessary.
`lwd` | A vector of line widths to be used for the various lines; recycled as necessary
`...` | Other graphic parameters passed to `lines`, e.g., `lty`

### Value

none

### Author(s)

Michael Friendly

### See Also

`lines`

### Examples

    if (require(vcd)) {
      data(PreSex, package="vcd")
      presex.mca <- mjca(PreSex)
      res <- plot(presex.mca, labels=0, pch='.', cex.lab=1.2)
      coords <- data.frame(res$cols, presex.mca$factors)
      nlev <- rle(as.character(coords$factor))$lengths
      fact <- unique(as.character(coords$factor))

      cols <- c("blue", "red", "brown", "black")
      lwd <- c(2, 2, 2, 4)

      plot(Dim2 ~ Dim1, type='n', data=coords)
      points(coords[,1:2], pch=rep(16:19, nlev), col=rep(cols, nlev), cex=1.2)
      text(coords[,1:2], labels=coords$level, col=rep(cols, nlev), pos=3, cex=1.2, xpd=TRUE)

      multilines(coords[, c("Dim1", "Dim2")], group=coords$factor, col=cols, lwd=lwd)
    }

[Package ca version 0.70 Index]