plotIndiv

Individuals representation

In this plot the samples are represented as point placed according to their relation to two dimensions among those chosen in the analysis (the ncomp parameter). Such points tends to aggregate together when they are share similarities.

Usage in mixOmics

Individual 2D plots can be obtained in mixOmics via the function plotIndiv as displayed below:

## We consider that we have the results of a sPLS computation on liver.toxicity
data(liver.toxicity)
X <- liver.toxicity$gene
Y <- liver.toxicity$clinic
result <- spls(X, Y, ncomp = 3, keepX = c(50, 50, 50), keepY = c(10, 10, 10))

## Choose the color for the different samples depending on the type of dose the
## rats undergo
liver.toxicity$treatment[, 3]
col <- rep(c("blue", "red", "darkgreen", "darkviolet"), c(16, 16, 16, 16))

## Choose different size of points
cex <- rep(c(1, 1.2, 1, 1.4), c(16, 16, 16, 16))

## Choose the form of the points (square, circle, triangle and diamond-shaped
pch <- rep(c(15, 16, 17, 18), c(16, 16, 16, 16))

## comp is the two dimensions you want to display
## ind.names is whether you want labels on each points
## rep.space determines the subspace to project the individuals ("X-variate",
## "Y-variate" or "XY-variate")
plotIndiv(result, comp = 1:2, ind.names = FALSE, rep.space = "X-variate",
          col = col, cex = cex, pch = pch)

It gives us this result:

Now lets add a legend to this graph.

## Same purpose as above
col <- c("blue", "red", "darkgreen", "darkviolet")
cex <- c(1, 1.2, 1, 1.4)
pch <- c(15, 16, 17, 18)

## The first two parameters are the x and y coordinates of the legend on the graph
## The third one is the text of the legend
legend(0.25, 0.4, c("50 mg/kg", "150 mg/kg", "1500 mg/kg", "2000 mg/kg"), col = col,
       pch = pch, pt.cex = cex, title = "Treatment")

script: 

You should have the following image: