prcompPlot {Harman} | R Documentation

## PCA plot

### Description

Generates a Principle Component plot for data.frames, matrices, or a pre-made `prcomp` object.

### Usage

    prcompPlot(object, pc_x = 1, pc_y = 2, scale = FALSE, colFactor = NULL,
      pchFactor = NULL, palette = "rainbow", legend = TRUE, ...)

### Arguments

`object` | data.frame, matrix or `prcomp` object.
`pc_x` | integer, principle component for the plot x dimension.
`pc_y` | integer, principle component for the plot y dimension.
`scale` | logical, whether to scale to unit variance before PCA.
`colFactor` | factor or vector, colour the points by this factor, default is `NULL`.
`pchFactor` | factor or vector, point-type by this factor, default is `NULL`.
`palette` | string, the function to call to create a vector of contiguous colours with `levels(colFactor)` steps.
`legend` | logical, whether to display a legend on the plot.
`...` | further arguments passed to or from other methods.

### Details

A data.frame object will be coerced internally to a matrix. Matrices must be of type `double` or `integer`. The `prcompPlot` function will then perform a principle component analysis on the data prior to plotting. The function is call is `prcomp(t(object), retx=TRUE, center=TRUE, scale.=scale)`. Instead of specifying a data.frame or matrix, a pre-made `prcomp` object can be given to `prcompPlot`. In this case, care should be taken in setting the appropriate value of `scale.`. If a vector is given to `colFactor` or `pchFactor`, they will be coerced internally to factors.

For the default `NULL` values of `colFactor` and `pchFactor`, all colours will be black and circles the point type, respectively.

### Value

None

### See Also

`prcomp` `rainbow`

### Examples

    library(HarmanData)
    data(IMR90)
    expt <- imr90.info$Treatment
    batch <- imr90.info$Batch
    prcompPlot(imr90.data, colFactor=expt)
    pca <- prcomp(t(imr90.data), scale.=TRUE)
    prcompPlot(pca, 1, 3, colFactor=batch, pchFactor=expt, palette='topo.colors',
    main='IMR90 PCA plot of Dim 1 and 3')

[Package Harman version 1.22.0 Index]