View source: R/SRPCAMS_methods.R
| plot.msPCA | R Documentation |
Generic plotting interface for objects of class "msPCA". Depending on the type argument,
this function visualizes loadings, scores, screeplots, biplots, or score distances.
## S3 method for class 'msPCA'
plot(x, type = c("loadings"), ...)
x |
An object of class |
type |
Type of plot to produce. One of: |
... |
Additional arguments passed to internal functions. |
If type = "loadings" a heatmap of loadings across groups is displayed. Optional input arguments are:
k | Integer. The k-th principal component will be plotted. |
text | Boolean, whether the loading values should also be displayed as text. Default FALSE. |
size | Numeric. Text size when text is TRUE. |
gnames | Character vector. Names for groups (shown in plots). |
cnames | Character vector. Names for variables (shown in plots). |
textrotate | Rotation angle of text in the heatmap. |
tolerance | Numeric, default 1e-04. Specifies the band of white color values around zero. |
If type = "screeplot" boxplots of the explained variance per component and cumulative variance per group are plotted. Optional input arguments are:
text | Boolean, whether the loading values should also be displayed as text. Default TRUE. |
size | Numeric. Text size when text is TRUE. |
gnames | Character vector. Names for groups (shown in plots). |
cutoff | Scalar with default value 0.8. The cumulative percentage cutoff value for the overall explained variance. |
textrotate | Rotation angle of text in the heatmap. |
If type = "biplot" the loadings are visualized in the first and second component over all groups. Optional input arguments are:
color | Character. Either "variable" (default) when the color should be connected to the variables or "groups" if the color should correspond to the groups. |
size | Numeric. Text size when text is TRUE. |
alpha | Alpha value for the loading points, default is 0.7 . |
If type = "scores" a histogram of the k-th scores per group are shown. Optional input arguments are:
k | Integer. The k-th principal component will be plotted. Default value is one. |
ssMRCD An object of class ssMRCD including list elements MRCDcov, MRCDmu, mX. Alternatively, X, groups, mu, Sigma can be provided..
X, groups, mu, Sigma The original data matrix, a vector of groups as for ssMRCD, a list of location vectors and a list of covariance matrices. |
|
Alternatively, a ssMRCD object can be given. |
|
alpha | Alpha value for histogramm, default is 0.7 . |
If type = "score_distances" a distance-distance plot of score and orthogonal distances is shown for each group. of the k-th scores per group are shown. Optional input arguments are:
k | Integer. Using the first k PCs for the distances. Default is the number of provided PCs.
ssMRCD An object of class ssMRCD including list elements MRCDcov, MRCDmu, mX. Alternatively, X, groups, mu, Sigma can be provided..
X, groups, mu, Sigma The original data matrix, a vector of groups as for ssMRCD, a list of location vectors and a list of covariance matrices. |
Alternatively, a ssMRCD object can be given. |
|
shape | Point shape. |
size | Numeric. Point size. |
alpha | Alpha value for the points, default is 0.7 . |
A ggplot2 object or list of plots, depending on the type.
msPCA, align,
screeplot.msPCA, , biplot.msPCA,
scores,
# set seed
set.seed(236)
# create data and setup
data = matrix(rnorm(2000), ncol = 4)
groups = sample(1:10, 500, replace = TRUE)
W = time_weights(N = 10, c(3,2,1))
# calculate covariances
covs = ssMRCD(data, groups = groups, weights = W, lambda = 0.3)
# calculate sparse PCA
pca = msPCA(eta = 1.3, gamma = 0.7, COVS = covs$MRCDcov)
# plot screeplot
plot(x = pca, type = "screeplot")
# align and plot loadings
pca$PC = align(PC = pca$PC, type = "mean")
plot(x = pca, type = "loadings", k = 1)
pca$PC = align(PC = pca$PC, type = "maxvar")
plot(x = pca, type = "loadings", k = 1)
pca$PC = align(PC = pca$PC, type = "largest")
plot(x = pca, type = "loadings", k = 1)
# plot different PCA plots
plot(x = pca, type = "score_distances", k = 2,
groups = groups, X = data, mu = covs$MRCDmu, Sigma = covs$MRCDcov)
plot(x = pca, type = "biplot", color = "variable")
plot(x = pca, type = "scores", ssMRCD = covs, k = 1)
plot(x = pca, type = "loadings", k = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.