Biplots in 3D

1 PCA 3D biplot

Three-dimensional PCA biplots are obtained by specifying dim.biplot = 3 in the call to PCA(). The package rgl is required and on calling the plot() the biplot is drawn in an rgl window. The plot can then be interactively rotated and zoomed using the mouse buttons.

biplot(iris) |> PCA(group.aes = iris$Species,dim.biplot = 3) |>
  axes(col="black") |> plot()

1.1 Adding new samples

The process of adding new samples to the biplot, called interpolation utilises the functions interpolate() and newsamples(). These functions work in the same way as in the call to the two-dimensional biplot. The function interpolate() accepts the argument newdata to specify a matrix or data frame containing the new samples to be interpolated. The function newsamples() operates the same way as samples() in that the user can specify the aesthetics of the interpolated samples.

biplot(iris[1:100,1:4])|> PCA(dim.biplot = 3) |> axes(col="black") |> 
  interpolate(newdata = iris[101:150,1:4]) |> newsamples(col="purple") |> plot()

1.2 Adding new variables

To interpolate new variables to the biplot, the function interpolate() and newaxes() are called. The function interpolate() accepts the argument newvariable to specify a matrix or data frame of the same number of rows in the data specified in biplot() containing the new variables to be interpolated. The function newaxes() allows the user to specify the aesthetics of the interpolated variables.

biplot(iris[,1:3])|> PCA(dim.biplot = 3) |> axes(col="black") |> 
  interpolate(newvariable = iris[,4]) |> 
  newaxes(col="darkred",X.new.names = "Petal.Width") |> plot()

1.3 Predicting samples

To add the prediction of samples on the biplot, the prediction() function is used. The predict.samples argument takes in a vector indicating either the row numbers of the samples to predict or set to TRUE indicating to predict all samples. The argument which allows the user to select which variable to predict the sample on. In the example below, samples 100 to 150 predictions are shown for variables 1 and 4. The aesthetics for the display of the predictions are arguments in the axes() function: predict.col and predict.lwd.

biplot(iris) |> PCA(group.aes = iris$Species,dim.biplot = 3,show.class.means = TRUE) |> 
  axes(col="black",predict.col = "orange") |>  
  prediction(predict.samples=100:150,which = c(1,4))  |> plot()

1.4 Predicting group means

Similarly, to add the prediction of group means, the function prediction() is used. The argument predict.means takes in a vector specifying which group means to predict. In the example below, only the first group means is predicted. Important to note that the argument show.class.means must be set to TRUE in the PCA() function.

biplot(iris) |> 
  PCA(group.aes = iris$Species,dim.biplot = 3,show.class.means = TRUE) |> 
  axes(col="black",predict.col = "darkred") |> 
  prediction(predict.means = 1) |> plot()

1.5 Ellipses

Ellipses are added to a 3D biplot using the ellipses() function which works in the same way as a 2D biplot.

biplot(iris) |> PCA(group.aes = iris[,5],dim.biplot = 3) |> 
  axes(col="black") |> 
  ellipses(kappa = 3,opacity = 0.5) |> plot()
#> Computing 3 -ellipse for setosa 
#> Computing 3 -ellipse for versicolor 
#> Computing 3 -ellipse for virginica