Learn R Programming

mixOmics (version 5.2.0)

plotIndiv: Plot of Individuals (Experimental Units)

Description

This function provides scatter plots for individuals (experimental units) representation in (sparse)(I)PCA, (regularized)CCA, (sparse)PLS(DA) and (sparse)(R)GCCA(DA).

Usage

plotIndiv(object,
           comp = NULL,
           rep.space = NULL,
           blocks = NULL, # to choose which block data to plot with GCCA module
           ind.names = TRUE,
           group,  
           col.per.group,
           style="ggplot2", # choose between graphics,3d, lattice or ggplot2
           plot.ellipse = FALSE,
           ellipse.level = 0.95,
           plot.centroid=FALSE,
           plot.star=FALSE,
           main=NULL,
           add.legend=FALSE,
           X.label = NULL,
           Y.label = NULL,
           Z.label = NULL,
           abline.line = FALSE,
           xlim = NULL,
           ylim = NULL,
           col,
           cex,
           pch,
           alpha=0.2,
           axes.box = "box",
           ...
)

Arguments

object
object of class inheriting from any mixOmics: PLS, sPLS, PLS-DA, SPLS-DA, rCC, PCA, sPCA, IPCA, sIPCA, rGCCA, sGCCA, sGCCDA
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.
rep.space
For objects of class "rcc", "pls", "spls", character string, (partially) matching one of "X-variate", "Y-variate" ,or "XY-variate", determining the subspace to project the indiv
blocks
integer value of name of a block to be plotted using the GCCA module. See examples.
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, useful for ellipse plots. Coded as default for the supervised methods PLS-DA, SPLS-DA,sGCCDA, but needs to be input for the unsupervised methods PCA, sPCA, IPCA, sIPCA, PLS, sPLS,
col.per.group
character (or symbol) color to be used when 'group' is defined. Vector of the same length than the number of groups.
style
argument to be set to either 'graphics', 'lattice', 'ggplot2' or '3d' for a style of plotting. Default set to 'ggplot2'. See details.
plot.ellipse
boolean indicating if ellipse plots should be plotted. In the non supervised objects PCA, sPCA, IPCA, sIPCA, PLS, sPLS, rCC, rGCCA, sGCCA ellipse plot is only be plotted if the argument group is provided. In the PLS-DA, SPL
ellipse.level
Numerical value indicating the confidence level of ellipse being plotted when plot.ellipse =TRUE (i.e. the size of the ellipse). The default is set to 0.95, for a 95% region.
plot.centroid
boolean indicating whether centroid points should be plotted. In the non supervised objects PCA, sPCA, IPCA, sIPCA, PLS, sPLS, rCC, rGCCA, sGCCA the centroid will only be plotted if the argument group is provided. The centroid w
plot.star
boolean indicating whether a star plot should be plotted, with arrows starting from the centroid (see argument plot.centroid, and ending for each sample belonging to each group or outcome. In the non supervised objects PCA, sPCA, IPCA,
main
set of characters indicating the title plot.
add.legend
boolean. Whether the legend should be added. Default is FALSE.
X.label
x axis titles.
Y.label
y axis titles.
Z.label
z axis titles (when style = '3d').
abline.line
should the vertical and horizontal line through the center be plotted? Default set to FALSE
xlim,ylim
numeric list of vectors of length 2 and length =length(blocks), giving the x and y coordinates ranges.
col
character (or symbol) color to be used, possibly vector.
cex
numeric character (or symbol) expansion, possibly vector.
pch
plot character. A character string or a vector of single characters or integers. See points for all alternatives.
alpha
Semi-transparent colors (0 < 'alpha' < 1)
axes.box
for style '3d', argument to be set to either 'axes', 'box', 'bbox' or 'all', defining the shape of the box.
...
external arguments or type par can be added with style = 'graphics'

encoding

latin1

Details

plotIndiv method makes scatter plot for individuals representation depending on the subspace of projection. Each point corresponds to an individual.

If ind.names=TRUE and row names is NULL, then ind.names=1:n, where n is the number of individuals.

The arguments col, cex and pch can be atomic vectors or vectors of length n. If atomic, this argument value determines the graphical attribute for all the individuals. In the last case, multiple arguments values can be specified so that each point (individual) can be given its own graphic attributes (see par). Default values exist for this arguments.

For customized plots (i.e. adding points, text), use the style = 'graphics' (default is ggplot2).

Note: the ellipse options were borrowed from the ellipse.

See Also

text, points and http://mixOmics.org/graphics for more details.

Examples

Run this code
## plot of individuals for objects of class 'rcc'
# ----------------------------------------------------
data(nutrimouse)
X <- nutrimouse$lipid
Y <- nutrimouse$gene
nutri.res <- rcc(X, Y, ncomp = 3, lambda1 = 0.064, lambda2 = 0.008)

# default, only in the X space
plotIndiv(nutri.res)

# ellipse with respect to genotype in the XY space,
    # names also indicate genotype
    plotIndiv(nutri.res, rep.space= 'XY-variate',
    plot.ellipse = TRUE, ellipse.level = 0.9,
    group = nutrimouse$genotype, ind.names = nutrimouse$genotype)

    # ellipse with respect to genotype in the XY space, with legend
    plotIndiv(nutri.res, rep.space= 'XY-variate', group = nutrimouse$genotype,
    add.legend = TRUE)


    # lattice style
    plotIndiv(nutri.res, rep.space= 'XY-variate', group = nutrimouse$genotype,
    add.legend = TRUE, style = 'lattice')

    # classic style, in the Y space
    plotIndiv(nutri.res, rep.space= 'Y-variate', group = nutrimouse$genotype,
    add.legend = TRUE, style = 'graphics')

## plot of individuals for objects of class 'pls' or 'spls'
# ----------------------------------------------------
data(liver.toxicity)
X <- liver.toxicity$gene
Y <- liver.toxicity$clinic
toxicity.spls <- spls(X, Y, ncomp = 3, keepX = c(50, 50, 50),
keepY = c(10, 10, 10))

#default
plotIndiv(toxicity.spls)


# indicating the centroid
plotIndiv(toxicity.spls, rep.space= 'X-variate', ind.names = FALSE,
          group = liver.toxicity$treatment[, 'Time.Group'], plot.centroid = TRUE)

# indicating the star and centroid
plotIndiv(toxicity.spls, rep.space= 'X-variate', ind.names = FALSE,
          group = liver.toxicity$treatment[, 'Time.Group'], plot.centroid = TRUE, plot.star = TRUE)


# indicating the star and ellipse
plotIndiv(toxicity.spls, rep.space= 'X-variate', ind.names = FALSE,
          group = liver.toxicity$treatment[, 'Time.Group'], plot.centroid = TRUE,
            plot.star = TRUE, plot.ellipse = TRUE)



# in the Y space, colors indicate time of necropsy, text is the dose
    plotIndiv(toxicity.spls, rep.space= 'Y-variate',
    group = liver.toxicity$treatment[, 'Time.Group'],
    ind.names = liver.toxicity$treatment[, 'Dose.Group'],
    add.legend = TRUE)

## plot of individuals for objects of class 'plsda' or 'splsda'
# ----------------------------------------------------
data(breast.tumors)
X <- breast.tumors$gene.exp
Y <- breast.tumors$sample$treatment

splsda.breast <- splsda(X, Y,keepX=c(10,10),ncomp=2)

# default option: note the outcome color is included by default!
plotIndiv(splsda.breast)

# default option with no ind name: pch and color are set automatically
    plotIndiv(splsda.breast, ind.names = FALSE, comp = c(1, 2))

    # default option with no ind name: pch and color are set automatically, with legend
    plotIndiv(splsda.breast, ind.names = FALSE, comp = c(1, 2), add.legend = TRUE)

    # trying the different styles
    plotIndiv(splsda.breast, ind.names = TRUE, comp = c(1, 2),
    plot.ellipse = TRUE, style = "ggplot2", cex = c(1, 1))
    plotIndiv(splsda.breast, ind.names = TRUE, comp = c(1, 2),
    plot.ellipse = TRUE, style = "lattice", cex = c(1, 1))

## variable representation for objects of class 'sgcca' (or 'rgcca')
# ----------------------------------------------------
data(nutrimouse)
Y = unmap(nutrimouse$diet)
data = list(gene = nutrimouse$gene, lipid = nutrimouse$lipid, Y = Y)
design1 = matrix(c(0,1,1,1,0,1,1,1,0), ncol = 3, nrow = 3, byrow = TRUE)
nutrimouse.sgcca <- wrapper.sgcca(blocks = data,
design = design1,
penalty = c(0.3, 0.5, 1),
ncomp = c(2, 2, 3),
scheme = "centroid",
verbose = FALSE,
bias = FALSE)

# default style: one panel for each block
plotIndiv(nutrimouse.sgcca)

# for the block 'lipid' with ellipse plots and legend, different styles
    plotIndiv(nutrimouse.sgcca, group = nutrimouse$diet, add.legend =TRUE,
    plot.ellipse = TRUE, ellipse.level = 0.5, blocks = "lipid", main = 'my plot')
    plotIndiv(nutrimouse.sgcca, style = "lattice", group = nutrimouse$diet,
    add.legend = TRUE, plot.ellipse = TRUE, ellipse.level = 0.5, blocks = "lipid",
    main = 'my plot')
    plotIndiv(nutrimouse.sgcca, style = "graphics", group = nutrimouse$diet,
    add.legend = TRUE, plot.ellipse = TRUE, ellipse.level = 0.5, blocks = "lipid",
    main = 'my plot')

## variable representation for objects of class 'sgccda'
# ----------------------------------------------------
# Note: the code differs from above as we use a 'supervised' GCCA analysis
data(nutrimouse)
Y = nutrimouse$diet
data = list(gene = nutrimouse$gene, lipid = nutrimouse$lipid)
design1 = matrix(c(0,1,0,1), ncol = 2, nrow = 2, byrow = TRUE)

nutrimouse.sgccda1 <- wrapper.sgccda(blocks = data,
Y = Y,
design = design1,
ncomp = c(2, 2),
keep = list(c(10,10), c(15,15)),
scheme = "centroid",
verbose = FALSE,
bias = FALSE)


# plotIndiv
# ----------
# displaying all blocks. bu default colors correspond to outcome Y
plotIndiv(nutrimouse.sgccda1)

# displaying only 2 blocks
    plotIndiv(nutrimouse.sgccda1, blocks = c(1,2), group = nutrimouse$diet)

    # with some ellipse, legend and title
    plotIndiv(nutrimouse.sgccda1, blocks = c(1,2), group = nutrimouse$diet,
    plot.ellipse = TRUE, add.legend = TRUE, main = 'my sample plot')

Run the code above in your browser using DataLab