Create an interactive 2D or 3D Plotly scatter plot from a PCA object created
by CreatePCAObject().
Arguments
- PCAObj
A PCA object returned by
CreatePCAObject(). Must containScoresandCombinedData.- Var
Optional character string naming a variable in
PCAObj$CombinedDataused to color points. Default isNULL.- t
Deprecated compatibility argument for color type. Use
ColorTypeinstead. If set to"Factor",Varis treated as categorical. Any other value treatsVaras continuous. Default is"NULL".- HoverVar
Optional character string naming one variable in
PCAObj$CombinedDatato display in hover text. Retained for backward compatibility. PreferHoverVarsfor new code. Default isNULL.- HoverVars
Optional character vector naming one or more variables in
PCAObj$CombinedDatato display in hover text. IfNULL, row number is shown. Default isNULL.- Components
Optional character or numeric vector specifying which score columns to plot. Supply two components for 2D or three components for 3D. If
NULL, the first three score columns are used.- Mode
Character. Either
"auto","3D", or"2D". If"auto", the plot dimension is inferred fromComponents. IfComponents = NULL,"auto"defaults to 3D. Default is"auto".- ColorType
Character. Either
"auto","factor", or"continuous"."auto"treats character, factor, logical, and labelled variables as categorical and numeric variables as continuous. Default is"auto".- Relabel
Logical. If
TRUE, labels attached to hover variables are used in hover text when available. IfFALSE, raw variable names are used. Default isTRUE.- Title
Optional plot title. Default is
NULL, which produces no title.
Details
By default, the function plots the first three score columns in
PCAObj$Scores using a 3D plot. These are not assumed to be named RC1,
RC2, and RC3; the function uses the current column order in
PCAObj$Scores. Users may manually specify which components to plot using
Components.
If Mode = "auto", the function chooses 2D when two components are supplied
and 3D when three components are supplied. If Components = NULL, it defaults
to the first three score columns and creates a 3D plot.
The function can optionally color points by a variable in
PCAObj$CombinedData and customize hover text using one or more variables.
When Relabel = TRUE, labels attached to hover variables are used in the
hover display when available.
Examples
# \donttest{
# Build a PCA object to plot
PCAObj <- CreatePCAObject(
data = mtcars,
VarsToReduce = names(mtcars),
numComponents = 3
)
# Default 3D scatter of the first three components
plotPCA(PCAObj)
# 2D scatter colored by a variable in the data
plotPCA(
PCAObj,
Components = c("RC1", "RC2"),
Mode = "2D",
Var = "cyl",
ColorType = "factor"
)
# Add hover information
plotPCA(
PCAObj,
Components = c("RC1", "RC2"),
Mode = "2D",
HoverVars = c("mpg", "hp")
)
# }
