Learn R Programming

rgr (version 1.1.0)

gx.rqpca.plot: Function to Plot Principal Component Analysis Loadings and Scores

Description

Function to display the results of a Principal Components Analysis (PCA) from the saved object from gx.mva or gx.robmva as biplots. Various options for displaying loadings and scores are available, see Details below.

Usage

gx.rqpca.plot(save, v1 = 1, v2 = 2, rplot = TRUE, qplot = TRUE,
	rowids = NULL, ifrot = TRUE, main = "", ...)

Arguments

save
a saved object from the execution of function gx.mva or gx.robmva.
v1
the component to be plotted on the x-axis of the biplot, default is the first component, v1 = 1.
v2
the component to be plotted on the y-axis of the biplot, default is the second component, v1 = 2.
rplot
the default is to plot the variables. If the variables are not required set rplot = FALSE. Note, if an ilr transform has been undertaken the loadings of the (p-1) synthetic variables will be displayed.
qplot
the default is to plot the observation (individual, case or sample) scores. If scores are not required set qplot = FALSE.
rowids
switch to determine if the input matrix row numbers are to be displayed instead of default plotting symbols. The default is for default plotting symbols, i.e. rowids = NULL, set rowids = TRUE if the row numbers
ifrot
by default the post-Varimax rotation scores are displayed if a rotation has been made, see gx.rotate. If rotated scores are available in the saved object but the unrotated biplot is to be displayed set <
main
an alternate plot title to that in the saved object, see Details below.
...
further arguments to be passed to methods concerning the plot. For example, if some colour other than black is required for the plotting characters, specify col = 2 to obtain red (see display.lty

Details

If main is undefined the name of the matrix object from which the PCA was derived is passed to the function via the saved object. Using the matrix name is the recommended procedure in the source functions as it helps to track the progression of the data analysis, acting as a record of the data source. However, at a presentation stage an alternate plot title may be preferred and can be defined in this function, e.g., main = "Plot Title Text". If no plot title is required set main = "". Information on the percentage of the variability explained by each component, and whether or not rotation has been undertaken, is recoved from the saved object and used to appropriately label the plot axes. The following describes the available plot option combinations, the first being the default: rplot = TRUE & qplot = TRUE & rowids = NULL, crosses (pch default) and variable names rplot = TRUE & qplot = FALSE & rowids = NULL, variable names only rplot = FALSE & qplot = TRUE & rowids = NULL, crosses (pch default) only rplot = FALSE & qplot = TRUE & rowids = TRUE, input matrix row numbers only rplot = TRUE & qplot = TRUE & rowids = TRUE, input matrix row numbers and variable names Because functions gx.mva and gx.robmva require a matrix as input the sample IDs that may be in a dataframe are lost. To plot in the component score space with Sample IDs, the scores can be recovered from the saved object, e.g., save$rqscore[, 1] and save$rqscore[, 2], and used as the x- and y-coordinates in function xyplot.tags with the sample IDs from the source dataframe. Appropriate plot and axis titling can be displayed by setting the function arguments by hand.

References

Reimann, C., Filzmoser, P., Garrett, R. and Dutter, R., 2008. Statistical Data Analysis Explained: Applied Environmental Statistics with R. John Wiley & Sons, Ltd., 362 p. Venables, W.N. and Ripley, B.D., 2001. Modern Applied Statistics with S-Plus, 3rd Edition, Springer, 501 p.

See Also

gx.mva, gx.robmva, xyplot.tags

Examples

Run this code
## Make test data available
data(sind)
attach(sind)
sind.mat <- as.matrix(sind[, -c(1:3)])
## Ensure all data are in the same units (mg/kg)
sind.mat2open <- sind.mat
sind.mat2open[, 2] <- sind.mat2open[, 2] * 10000

## Save PCA results and display biplots
sind.save <- gx.mva(clr(sind.mat2open))
gx.rqpca.plot(sind.save)
gx.rqpca.plot(sind.save,
main = "Howarth & Sinding Larsen Stream Sediments
clr transform",
pch = 4, cex.main = 0.9)
gx.rqpca.plot(sind.save, rplot = TRUE, qplot = FALSE, rowids = NULL)
gx.rqpca.plot(sind.save, rplot = FALSE, qplot = TRUE, rowids = NULL)
gx.rqpca.plot(sind.save, rplot = FALSE, qplot = TRUE, rowids = TRUE,
cex = 0.9)
gx.rqpca.plot(sind.save, rplot = TRUE , qplot = TRUE, rowids = TRUE,
cex = 0.9)
#
attach(sind)
xyplot.tags(sind.save$rqscore[, 1],sind.save$rqscore[, 2], ID, cex = 0.9)

## Clean-up and detach test data
rm(sind.mat)
rm(sind.mat2open)
rm(sind.save)
detach(sind)

Run the code above in your browser using DataLab