View source: R/user_functions.R
heatmap_loading | R Documentation |
Plot a heatmap of the standardized loadings from a PCA solution.
heatmap_loading( pca, pca_data, ndim = 1:10, cutoff = 0, legend_title = "s. loading", text_values = TRUE, star_values = F, text_size = 2, vars = NULL, colors = c("steelblue1", "white", "firebrick1") )
pca |
Object of class prcomp, princals, or data.frame. If object is a prcomp or princals object, pca_data is required, and the loadings will be extracted. If object is a data.frame object, the dataframe needs to be formatted as: first column named Variables and all other columns corresponding to a PC. One row per variable. The values are the loadings. |
pca_data |
Data passed to the prcomp or princals function. |
ndim |
Numeric. Number of PCs to plot |
cutoff |
Numeric or numeric vector of length ndim. Value of the loadings threshold (i.e. |loadings| >= cutoff) to plot with stars. Default = 0 |
legend_title |
String. Title of the legend. 's. loading' by default. |
text_values |
Logical. Whether to plot the values of the loadings or not. Default= TRUE |
star_values |
Logical. Whether to plot a star in |loadings|>=cutoff. Only relevant if text_values=FALSE. Default=FALSE |
text_size |
Numeric. Size of the text_values. |
vars |
Character vector. Variables will be ordered as the provided variable names. Non-specified variables will be excluded from the plot. By default variables are ordered in alphabetically by ggplot. |
colors |
Character vector of length 3. Vector with the character name or hexadecimal number (e.g. "#FF0000") of three colors, the lower color, the middle color and the higher color for the gradient used in the plot. Hexadecimal number can be obtained using rgb for example. |
Returns a ggplot2 object.
Abel Torres Espin
data(mtcars) pca_mtcars<-prcomp(mtcars, center = TRUE, scale. = TRUE) heatmap_loading(pca = pca_mtcars, pca_data = mtcars, ndim = 1:4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.