plotIndiv | R Documentation |
This function provides scatter plots for individuals (observations) representation in (s)(I)PCA, (r)CCA, (s)PLS(DA), multiblock (s)PLS(DA) and MINT models.
plotIndiv(object, ...)
## S3 method for class 'mint.pls'
plotIndiv(
object,
comp = NULL,
rep.space = NULL,
study = "global",
layout = NULL,
style = "ggplot2",
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
background = NULL,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
xlim = NULL,
ylim = NULL,
abline = FALSE,
point.lwd = 1,
cex,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'mint.spls'
plotIndiv(
object,
comp = NULL,
rep.space = NULL,
study = "global",
layout = NULL,
style = "ggplot2",
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
background = NULL,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
xlim = NULL,
ylim = NULL,
abline = FALSE,
point.lwd = 1,
cex,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'mint.plsda'
plotIndiv(
object,
comp = NULL,
rep.space = NULL,
study = "global",
layout = NULL,
style = "ggplot2",
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
background = NULL,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
xlim = NULL,
ylim = NULL,
abline = FALSE,
point.lwd = 1,
cex,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'mint.splsda'
plotIndiv(
object,
comp = NULL,
rep.space = NULL,
study = "global",
layout = NULL,
style = "ggplot2",
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
background = NULL,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
xlim = NULL,
ylim = NULL,
abline = FALSE,
point.lwd = 1,
cex,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'pca'
plotIndiv(
object,
comp = NULL,
style = "ggplot2",
ind.names = TRUE,
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
pch,
title = NULL,
legend = FALSE,
legend.title.pch = "Legend",
legend.title = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
Z.label = NULL,
xlim = NULL,
ylim = NULL,
axes.box = "box",
abline = FALSE,
cex,
alpha = 0.2,
point.lwd = 1,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'mixo_pls'
plotIndiv(
object,
comp = NULL,
rep.space = NULL,
style = "ggplot2",
ind.names = TRUE,
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
background = NULL,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.title.pch = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
Z.label = NULL,
abline = FALSE,
xlim = NULL,
ylim = NULL,
axes.box = "box",
cex,
alpha = 0.2,
point.lwd = 1,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'sgcca'
plotIndiv(
object,
comp = NULL,
blocks = NULL,
style = "ggplot2",
ind.names = TRUE,
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.title.pch = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
Z.label = NULL,
abline = FALSE,
xlim = NULL,
ylim = NULL,
axes.box = "box",
cex,
alpha = 0.2,
point.lwd = 1,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
## S3 method for class 'rgcca'
plotIndiv(
object,
comp = NULL,
blocks = NULL,
style = "ggplot2",
ind.names = TRUE,
group,
col,
ellipse = FALSE,
ellipse.level = 0.95,
centroid = FALSE,
star = FALSE,
pch,
title = NULL,
subtitle,
legend = FALSE,
legend.title = "Legend",
legend.title.pch = "Legend",
legend.position = "right",
X.label = NULL,
Y.label = NULL,
Z.label = NULL,
abline = FALSE,
xlim = NULL,
ylim = NULL,
axes.box = "box",
cex,
alpha = 0.2,
point.lwd = 1,
size.title = rel(2),
size.subtitle = rel(1.5),
size.xlabel = rel(1),
size.ylabel = rel(1),
size.axis = rel(0.8),
size.legend = rel(1),
size.legend.title = rel(1.1),
...
)
object |
object of class inherited from any mixOmics: |
... |
Optional arguments or type par can be added with |
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 |
- only for objects of class |
study |
- only for MINT models. Indicates whether to plot all studies together
|
layout |
layout parameter passed to mfrow. Only for MINT model and only
used when |
style |
argument to be set to either |
group |
factor indicating the group membership for each sample, useful
for colouring samples by groups, adding ellipses, centroids and stars.
Coded as default for the supervised methods |
col |
character (or symbol) color to be used. If |
ellipse |
Logical indicating if ellipse plots should be plotted. See details. |
ellipse.level |
Numerical value indicating the confidence level of
ellipse being plotted when |
centroid |
Logical indicating whether centroid points should be plotted. See details. |
star |
Logical indicating whether a star plot should be plotted, with
arrows starting from the centroid (see argument |
background |
color the background by the predicted class, see
|
pch |
value or vector, controls shape of points to be plotted. Can be used to control the shape of the points directly or to create a second group membership and legend. See details. |
title |
set of characters indicating the title plot. |
subtitle |
subtitle for each plot, only used when several |
legend |
Logical. Whether the legend should be added. Default is FALSE. |
legend.title |
title of the legend |
legend.position |
position of the legend, one of "bottom", "left", "top" and "right". |
X.label |
x axis titles. |
Y.label |
y axis titles. |
xlim , ylim |
numeric list of vectors of length 2 and length =length(blocks), giving the x and y coordinates ranges. |
abline |
should the vertical and horizontal line through the center be
plotted? Default set to |
point.lwd |
|
cex |
numeric character (or symbol) expansion, possibly vector. |
size.title |
size of the title |
size.subtitle |
size of the subtitle |
size.xlabel |
size of xlabel |
size.ylabel |
size of ylabel |
size.axis |
size of the axis |
size.legend |
size of the legend |
size.legend.title |
size of the legend title |
ind.names |
either a character vector of names for the individuals to
be plotted, or |
legend.title.pch |
title of the second legend created by |
Z.label |
z axis titles (when style = '3d'). |
axes.box |
for style '3d', argument to be set to either |
alpha |
Semi-transparent colors (0 < |
blocks |
- only for multiblock objects. Integer value or name(s) of block(s) to be plotted OR "average" (averages the components from all blocks to produce a consensus plot) OR "weighted.average" (weighted average of the components according to their correlation with the outcome Y). See examples. |
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. Also, if
pch
is an input, then ind.names
is set to FALSE as we do not
show both names and shapes.
The outputs of "ellipse", "ellipse.level", "centroid", "star"
are:
1) based on the sample group membership (specified with the group
) for unsupervised
models such as PCA, sPCA, IPCA, sIPCA, PLS, sPLS, rCC, rGCCA,
sGCCA
or 2) based on the outcome Y
for supervised models such as PLS-DA, SPLS-DA,sGCCDA
#' In the specific case of a single 'omics supervised model
(plsda
, splsda
), users can overlay prediction
results to sample plots in order to visualise the prediction areas of each
class, via the background
input parameter. Note that this
functionality is only available for models with less than 2 components as
the surfaces obtained for higher order components cannot be projected onto a
2D representation in a meaningful way. For more details, see
background.predict
The group
parameter is used to colour the samples by group membership, and by
default the shape of samples will also correspond to these groups. Sample shapes can
be further customised using the pch
parameter. This can be done in 3 ways:
1) If pch
is one numeric value, shape of all points will be this.
2) If pch
is a vector of numeric values length equal to the number of groups
set in group
, then each group will have the given different shape.
3) If pch
is a character vector of length equal to the number of samples, then the
shape of each sample will correspond to this grouping, i.e. this allows users to visualise
second group membership. In case 3), the elements of the vector should be the names of the
second group membership, as these will appear in the legend. The shapes of the second group
membership will be 1, 2, 3, etc by default, control of the shape is only possible by
reordering the levels of the second group membership.
See examples.
For customized plots (i.e. adding points, text), use the style = 'graphics' (default is ggplot2).
Note: the ellipse options were borrowed from the ellipse.
none
Ignacio González, Benoit Gautier, Francois Bartolo, Florian Rohart, Kim-Anh Lê Cao, Al J Abadi
text
, background.predict
,
points
and http://mixOmics.org/graphics for more details.
## 'pca' class - examples demonstrate how to control sample colours and shapes
# -----------------------------------------------------------------------------
# subset data and create model
data("srbct")
X <- srbct$gene[1:6, ]
rownames(X) <- c(paste0("Sample_", 1:6))
pca.obj <- pca(X, ncomp = 3)
primary_groups <- as.factor(c(rep("Group_1", 2), rep("Group_2", 2), rep("Group_3", 2)))
# [1] Group_1 Group_1 Group_2 Group_2 Group_3 Group_3
# Levels: Group_1 Group_2 Group_3
secondary_groups <- as.factor(c(rep("A", 3), rep("B", 2), rep("C", 1)))
# [1] A A A B B C
# Levels: A B C
# plot samples coloured by primary groups, show sample names
plotIndiv(pca.obj, ind.names = TRUE,
group = primary_groups, legend = TRUE)
# plot samples coloured using custom colours by primary groups, show sample names
plotIndiv(pca.obj, ind.names = TRUE,
group = primary_groups, legend = TRUE,
col = c("red", "pink", "blue"))
# plot samples coloured by primary groups, by default shapes match primary groups
plotIndiv(pca.obj, ind.names = FALSE,
group = primary_groups, legend = TRUE)
# plot samples coloured by primary groups, force all samples to have the same shape (2 = triangle)
plotIndiv(pca.obj, ind.names = FALSE,
group = primary_groups, legend = TRUE,
pch = 2)
# plot samples coloured by primary groups, use shapes to visualise secondary grouping
plotIndiv(pca.obj, ind.names = FALSE,
group = primary_groups, legend = TRUE,
pch = secondary_groups)
# plot samples coloured by primary groups, use shapes to visualise secondary grouping
# and change order of secondary groups
plotIndiv(pca.obj, ind.names = FALSE,
group = primary_groups, legend = TRUE,
pch = factor(secondary_groups, levels = c("B", "C", "A")))
## 'rcc' class - examples demonstrate how to control rep.space
# ------------------------------------------------------------
# create model
data(nutrimouse)
X <- nutrimouse$lipid
Y <- nutrimouse$gene
rcc.obj <- rcc(X, Y, ncomp = 3, lambda1 = 0.064, lambda2 = 0.008)
# plot samples, by default makes a panel plot for X and Y subspaces (multi)
plotIndiv(rcc.obj)
# plot samples only on X-variate subspace
plotIndiv(rcc.obj, rep.space = "X-variate")
# plot samples only on XY-variate subspace
plotIndiv(rcc.obj, rep.space = "XY-variate")
## 'spls' class - examples demonstrate how to add ellipses and centroids/stars on groups
# --------------------------------------------------------------------------------------
# create model
data(liver.toxicity)
X <- liver.toxicity$gene
Y <- liver.toxicity$clinic
spls.obj <- spls(X, Y, ncomp = 3, keepX = c(50, 50, 50),
keepY = c(10, 10, 10))
# plot samples with ellipse on groups
plotIndiv(spls.obj, group = liver.toxicity$treatment$Time.Group, ellipse = TRUE)
# plot samples with centroids on groups
plotIndiv(spls.obj, group = liver.toxicity$treatment$Time.Group, centroid = TRUE)
# plot samples with centroids and stars on groups
plotIndiv(spls.obj, group = liver.toxicity$treatment$Time.Group, centroid = TRUE, star = TRUE)
## 'splsda' class - examples demonstrate how to add ellipses and backgrounds based on
# predicted classes
# ------------------------------------------------------------------------------------
# create model
data(breast.tumors)
X <- breast.tumors$gene.exp
Y <- breast.tumors$sample$treatment
splsda.obj <- splsda(X, Y,keepX=c(10,10),ncomp=2)
# plot samples with ellipse on groups, note groups do not have to be defined
plotIndiv(splsda.obj, ellipse = TRUE, ellipse.level = 0.8)
# plot samples with background coloured by predicted classes
background <- background.predict(splsda.obj, comp.predicted = 2, dist = "max.dist")
plotIndiv(splsda.obj, background = background)
## 'sgccda' class - examples demonstrate how to control which data blocks are plotted
# ------------------------------------------------------------------------------------
# create model
data(nutrimouse)
Y <- nutrimouse$diet
data <- list(gene = nutrimouse$gene, lipid = nutrimouse$lipid)
design <- matrix(c(0,1,0,1), ncol = 2, nrow = 2, byrow = TRUE)
sgccda.obj <- wrapper.sgccda(X = data, Y = Y, design = design, ncomp = 2,
keepX = list(gene = c(10,10), lipid = c(15,15)))
# plot samples, by default one data block for each plot
plotIndiv(sgccda.obj)
# plot samples for just the gene data block
plotIndiv(sgccda.obj, blocks = 1)
plotIndiv(sgccda.obj, blocks = "gene")
# plot samples by averaging components from all blocks
plotIndiv(sgccda.obj, blocks = "average")
# plot samples by the weighted average of the components according to their correlation
# with Y
plotIndiv(sgccda.obj, blocks = "weighted.average")
## 'mint.splsda' class - examples demonstrate how to control which studies are plotted
# ------------------------------------------------------------------------------------
# create model
data(stemcells)
mint.obj <- mint.splsda(X = stemcells$gene, Y = stemcells$celltype, ncomp = 2,
keepX = c(10, 5), study = stemcells$study)
# plot samples, by default samples are plotted together coloured by groups and pch by study
plotIndiv(mint.obj, legend = TRUE)
# plot samples separated by study, can control layout
plotIndiv(mint.obj, legend = TRUE, study = "all.partial")
plotIndiv(mint.obj, legend = TRUE, study = "all.partial", layout = c(1,1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.