0

I have calculated PCA scores and loadings using SPSS software. Now I want to generate biplot like fviz_pca_biplot function of factoextra package. I am using the following code

library(FactoMineR)
library(factoextra)
library(tidyverse)

#Plot
scores %>%
  ggplot(mapping = aes(x=PC1, y=PC2)) +
  geom_point(aes(fill=Treatments), shape = 21, size = 2, colour = "black") +
  geom_text(aes(x = PC1 * 1.07, y = PC2 * 1.07,
                label = Treatments)) +
  geom_segment(data = loadings,
               aes(x = 0, y = 0, xend = PC1, yend = PC2, group = Variables),
               arrow = arrow(length = unit(4, "mm")),
               color = "red") +
  geom_text(data = loadings,
            aes(x = PC1 * 1.15, y = PC2 * 1.15, label = Variables),
            colour = "red")+
  geom_hline(yintercept = 0, lty = 2) +
  geom_vline(xintercept = 0, lty = 2)+
  xlab("PC1 (73.28%)") + 
  ylab("PC2 (13.04%)") +
  theme_bw() + 
  theme(legend.position = "none")

which gives me following plot

enter image description here

Now how can I have the plot like the following

enter image description here

Also, the loading plot from

ggplot() +
  geom_segment(data = loadings,
             aes(x = 0, y = 0, xend = PC1, yend = PC2, group = Variables),
             arrow = arrow(length = unit(4, "mm")),
             color = "red") +
  geom_text(data = loadings,
            aes(x = PC1 * 1.15, y = PC2 * 1.15, label = Variables),
            colour = "red")+
  geom_hline(yintercept = 0, lty = 2) +
  geom_vline(xintercept = 0, lty = 2)+
  xlab("PC1 (73.28%)") + 
  ylab("PC2 (13.04%)") +
  theme_bw() + 
  theme(legend.position = "none")

enter image description here

to

enter image description here

Data

loadings = structure(list(Variables = c("Prop1", "Prop2", "Prop3", "Prop4", 
"Prop5", "Prop6", "Prop7", "Prop8", "Prop9", "Prop10", "Prop11", 
"Prop12", "Prop13", "Prop14", "Prop15", "Prop16"), PC1 = c(0.908, 
0.795, 0.921, 0.898, 0.889, 0.963, 0.93, 0.975, 0.172, 0.591, 
0.831, 0.861, -0.239, 0.91, 0.253, 0.453), PC2 = c(0.231, 0.579, 
0.271, 0.418, 0.402, 0.209, 0.311, 0.127, 0.039, 0.678, 0.438, 
0.387, 0.089, 0.262, 0.953, 0.779), PC3 = c(-0.025, -0.072, -0.09, 
-0.028, 0.02, -0.007, 0.075, -0.042, 0.952, -0.386, -0.229, -0.148, 
0.891, 0.103, 0.121, 0.28)), row.names = c(NA, 16L), class = "data.frame")

scores = structure(list(Treatments = c("T1", "T2", "T3", "T4", "T5", "T6", 
"T7", "T8", "T9", "T10"), PC1 = c(-1.47668, -0.66494, -0.50253, 
-0.32421, -0.01627, 1.68253, 1.7172, -0.21214, -0.39649, 0.19354
), PC2 = c(-1.69723, -0.38506, 1.29607, 0.37729, 0.99437, -0.45377, 
-0.54451, -0.99605, 1.28462, 0.12429), PC3 = c(-0.68648, 1.33871, 
-0.19289, -0.7935, 1.58389, 0.20006, -0.29374, 0.89644, -0.51398, 
-1.5385)), row.names = c(NA, 10L), class = "data.frame")
UseR10085
  • 7,120
  • 3
  • 24
  • 54

0 Answers0