biplot: biplot methods for 'pca' family

biplotR Documentation

biplot methods for pca family

Description

biplot methods for pca family

Usage

## S3 method for class 'pca'
biplot(
  x,
  comp = c(1, 2),
  block = NULL,
  ind.names = TRUE,
  group = NULL,
  cutoff = 0,
  col.per.group = NULL,
  col = NULL,
  ind.names.size = 3,
  ind.names.col = color.mixo(4),
  ind.names.repel = TRUE,
  pch = 19,
  pch.levels = NULL,
  pch.size = 2,
  var.names = TRUE,
  var.names.col = "grey40",
  var.names.size = 4,
  var.names.angle = FALSE,
  var.arrow.col = "grey40",
  var.arrow.size = 0.5,
  var.arrow.length = 0.2,
  ind.legend.title = NULL,
  vline = FALSE,
  hline = FALSE,
  legend = if (is.null(group)) FALSE else TRUE,
  legend.title = NULL,
  pch.legend.title = NULL,
  cex = 1.05,
  ...
)

## S3 method for class 'mixo_pls'
biplot(
  x,
  comp = c(1, 2),
  block = NULL,
  ind.names = TRUE,
  group = NULL,
  cutoff = 0,
  col.per.group = NULL,
  col = NULL,
  ind.names.size = 3,
  ind.names.col = color.mixo(4),
  ind.names.repel = TRUE,
  pch = 19,
  pch.levels = NULL,
  pch.size = 2,
  var.names = TRUE,
  var.names.col = "grey40",
  var.names.size = 4,
  var.names.angle = FALSE,
  var.arrow.col = "grey40",
  var.arrow.size = 0.5,
  var.arrow.length = 0.2,
  ind.legend.title = NULL,
  vline = FALSE,
  hline = FALSE,
  legend = if (is.null(group)) FALSE else TRUE,
  legend.title = NULL,
  pch.legend.title = NULL,
  cex = 1.05,
  ...
)

Arguments

x

An object of class 'pca'or mixOmics '(s)pls'.

comp

integer vector of length two (or three to 3d). The components that will be used on the horizontal and the vertical axis respectively to project the individuals.

block

Character, name of the block to show for pls object. Default to 'X'.

ind.names

either a character vector of names for the individuals to be plotted, or FALSE for no names. If TRUE, the row names of the first (or second) data matrix is used as names (see Details).

group

Factor indicating the group membership for each sample.

cutoff

numeric between 0 and 1. Variables with correlations below this cutoff in absolute value are not plotted (see Details).

col.per.group

character (or symbol) color to be used when 'group' is defined. Vector of the same length as the number of groups.

col

character (or symbol) color to be used, possibly vector.

ind.names.size

Numeric, sample name size.

ind.names.col

Character, sample name colour.

ind.names.repel

Logical, whether to repel away label names.

pch

plot character. A character string or a vector of single characters or integers. See points for all alternatives.

pch.levels

If pch is a factor, a named vector providing the point characters to use. See examples.

pch.size

Numeric, sample point character size.

var.names

Logical indicating whether to show variable names. Alternatively, a character.

var.names.col

Character, variable name colour.

var.names.size

Numeric, variable name size.

var.names.angle

Logical, whether to align variable names to arrow directions.

var.arrow.col

Character, variable arrow colour. If 'NULL', no arrows are shown.

var.arrow.size

Numeric, variable arrow head size.

var.arrow.length

Numeric, length of the arrow head in 'cm'.

ind.legend.title

Character, title of the legend.

vline

Logical, whether to draw the vertical neutral line.

hline

Logical, whether to draw the horizontal neutral line.

legend

Logical, whether to show the legend if group != NULL.

legend.title

Character, the legend title if group != NULL.

pch.legend.title

Character, the legend title if pch is a factor.

cex

Numeric scalar indicating the desired magnification of plot texts. theme function may be used with the output object if further customisation is required.

...

Not currently used.

pch.legend

Character, the legend title if pch is a factor.

Details

biplot unifies the reduced representation of both the observations/samples and variables of a matrix of multivariate data on the same plot. Essentially, in the reduced space the samples are shown as points/names and the contributions of features to each dimension are shown as directed arrows or vectors. For pls objects it is possible to use either 'X' or 'Y' latent space using block argument.

Value

A ggplot object.

Author(s)

Al J Abadi

Examples

data("nutrimouse")
## --------- pca ---------- ##
pca.lipid <- pca(nutrimouse$lipid, ncomp = 3, scale = TRUE)
# seed for reproducible geom_text_repel
set.seed(42)
biplot(pca.lipid)
## correlation cutoff to filter features
biplot(pca.lipid, cutoff = c(0.8))
## tailor threshold for each component
biplot(pca.lipid, cutoff = c(0.8, 0.7))
## customise components
biplot(pca.lipid, cutoff = c(0.8), comp = c(1,3))

## customise ggplot in an arbitrary way
biplot(pca.lipid) + theme_linedraw() + 
    # add vline
    geom_vline(xintercept = 0, col = 'green') +
    # add hline
    geom_hline(yintercept = 0, col = 'green') +
    # customise labs
    labs(x = 'Principal Component 1', y = 'Principal Component 2')

## group samples
biplot(pca.lipid, group = nutrimouse$diet, legend.title = 'Diet')

## customise variable labels
biplot(pca.lipid, 
       var.names.col = color.mixo(2),
       var.names.size = 4,
       var.names.angle = TRUE
)

## no arrows
biplot(pca.lipid, group = nutrimouse$diet, legend.title = 'Diet', 
       var.arrow.col = NULL, var.names.col = 'black')

## add x=0 and y=0 lines in function
biplot(pca.lipid, group = nutrimouse$diet, legend.title = 'Diet', 
       var.arrow.col = NULL, var.names.col = 'black', 
       vline = TRUE, hline = TRUE)

## --------- spca
## example with spca
spca.lipid <- spca(nutrimouse$lipid, ncomp = 2, scale = TRUE, keepX = c(8, 6))
biplot(spca.lipid, var.names.col = 'black', group = nutrimouse$diet, 
       legend.title = 'Diet')

## --------- pls ---------- ##
data("nutrimouse")
pls.nutrimouse <- pls(X = nutrimouse$gene, Y = nutrimouse$lipid, ncomp = 2)
biplot(pls.nutrimouse, group = nutrimouse$genotype, block = 'X',
       legend.title = 'Genotype', cutoff = 0.878) 

biplot(pls.nutrimouse, group = nutrimouse$genotype, block = 'Y',
       legend.title = 'Genotype', cutoff = 0.8) 

## --------- plsda ---------- ##
data(breast.tumors)
X <- breast.tumors$gene.exp
colnames(X) <- paste0('GENE_', colnames(X))
rownames(X) <- paste0('SAMPLE_', rownames(X))
Y <- breast.tumors$sample$treatment

plsda.breast <- plsda(X, Y, ncomp = 2)
biplot(plsda.breast, cutoff = 0.72)
## remove arrows
biplot(plsda.breast, cutoff = 0.72, var.arrow.col = NULL, var.names.size = 4)

mixOmicsTeam/mixOmics documentation built on Nov. 19, 2024, 11:53 a.m.