plot_pca: Plot PCA results

Description Usage Arguments Value Examples

Description

inputs:

Usage

1
2
3
4
5
plot_pca(x, npcs = c(1, 2), xlab = NULL, ylab = NULL, zlab = NULL,
  main = "PCA results", pch = NULL, col = NULL, bg = NULL, cex = NULL,
  pal = RColorBrewer::brewer.pal(8, "Dark2"), add.legend = FALSE,
  legend.position = "bottomleft", legend.text = NULL, legend.col = NULL,
  legend.bg = NULL, legend.inset = 0, ...)

Arguments

x:

data frame, matrix or prcomp object to plot.

npcs:

numeric vector indicating PCs to plot, defaults to c(1,2). If length(npcs)>3, only the first 3 elements will be used.

xlab:

xlabel, see par.

ylab:

ylabel, see par, see par.

zlab:

zlabel, see plot3d.

main:

title for the plot, see par. Defaults to 'PCA results'.

pch:

numeric vector of plotting characters, see par.

col:

vector of plotting character colors, see par.

bg:

vector of plotting character background colors, see par.

cex:

plotting character size. Defaults to 1 for 2D and to 7 for 3D plots.

pal:

color palette. Defaults to the colorblind friendly RColorBrewer::brewer.pal(8,"Dark2"). Setting pal to NULL, will lead to the default R colors being used in the plots.

add.legend:

add a legend to the plot, defaults to FALSE.

legend.position:

, argument to legend. Position of the legend in the plot, defaults to 'bottomleft'.

legend.text:

character vector to appear in the legend.

legend.col:

color of legend elements, defaults to unique(col)

legend.bg:

background color of legend elements, defaults to unique(bg)

legend.inset:

inset distance(s) from the margins as a fraction of the plot region when legend is placed by keyword

...:

arguments passed to the plot() or rgl::plot3d() functions

Value

a list with class "prcomp", containing the same elements as prcomp:

Examples

1
2
3
4
5
6
7
data(iris)

# 2D PCA
plot_pca(x=iris[1:4],col=iris$Species)

# 3D PCA
plot_pca(x=iris[1:4],npcs=3,col=iris$Species)

nchlis/pca.utils documentation built on May 23, 2019, 1:06 p.m.