pca_plots | R Documentation |
Generate different plots for a PCA analysis. Score plot (includings Hotelling T2 confidence interval ellipse), loading plot or a summary plot. The summary plot contains a score plot, loadings plot and the summary of fit plot.
pca_plots( data, x, y, type = c("scores", "loadings", "summary"), T2 = TRUE, hotelling = 0.95, colour = NULL, shape = NULL, size = 3 )
data |
dataframe containing all information. See details for more information on the structure. |
x |
Principal component for the x-axis. |
y |
Principal component for the y-axis. |
type |
Which plot to generate: scores, loadings or summary plot. |
T2 |
add a Hotteling T2 ellipse to the scores plot. Default is true. |
hotelling |
Set the Hotelling confidence interval. Default = 0.95. |
colour |
Set the color of the points for different groups. |
shape |
Set the shape of the points for different groups. |
size |
Set the size of the points. Default is 3. |
data
should be data frame which contains at least 2 variables
for plotting the scores or loadings plot. The name of these 2 variables are
also used as label for the axes. More variables can be added for coloring
or shaping the points. These variables should be factors. See the examples
for a simple example.
A ggplot2 plot is returned.
Rico Derks
# create a dummy frame mydata <- data.frame(PC1 = rnorm(40), PC2 = rnorm(40), groups = as.factor(c(rep(1, 20), rep(2, 20))), shapes = as.factor(c(rep(1, 20), rep(2, 20)))) p <- pca_plots(data = mydata, x = PC1, y = PC2, type = "scores", colour = groups, shape = shapes) # or library(dplyr) mydata %>% pca_plots(x = PC1, y = PC2, type = "scores", colour = groups, shape = shapes)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.