[英]How to display observations in pca biplot?
I'm hoping to display observation row names on a principal component analysis biplot using the factoextra package.我希望使用 factoextra 包在主成分分析双图上显示观察行名称。
library(factoextra)
## organize dataset to obtain unique rownames
iris$id <- rownames(iris)
iris$id <- paste(iris$Species, iris$id, sep="_")
rownames(iris) <- iris$id
iris <- iris[,1:4]
## Run PCA
pca <- prcomp(iris, center=T, scale. = T)
## On this plot observation names are displayed
fviz_pca_ind(pca,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE
)
## Is there any way to display the same row names in this plot? (instead of points)
fviz_pca_biplot(pca,
col.var = "#2E9FDF", # Variables color
col.ind = "#696969", # Individuals color
label = 'var',
repel = TRUE
)
Thanks in advance提前致谢
You can specify geom.ind = "txt"您可以指定 geom.ind = "txt"
fviz_pca_biplot(pca,geom.ind="text",labelsize=2,
col.var = "#2E9FDF",col.ind = "#696969")
And try to add the ggrepel :并尝试添加 ggrepel :
options(ggrepel.max.overlaps = 20)
fviz_pca_biplot(pca,geom.ind="text",labelsize=2,
col.var = "#2E9FDF",col.ind = "#696969",repel=TRUE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.