R语言 删除PCA fviz_pca_biplot中点的ID样本,同时保留向量上的标签

p5fdfcr1  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(179)

我正在使用fviz_pca_biplot进行PCA,希望删除我的点的ID以使PCA更清晰。我希望保留我的矢量标签。
我应该使用什么命令来删除ID?
这是我的代码和结果。

pca_biplot = fviz_pca_biplot(res.pca, repel = TRUE, max.overlaps=Inf,
               col.var = "#000000", # Variables color #colour of the lines
               #colour = Population, #sets the colour of the data to be determined by population
               axes = c(3, 4), # choose PCs to plot
               habillage = data$Population,
               col.ind = "#696969", #colour of points
               labels=NULL
               )

pca_biplot + 
  labs(title ="ACP", x = "CP3 (15,3%)", y = "CP4 (9,6%)") + 
  scale_color_manual(values = c("blue","red")) + 
  theme_minimal()

我还写了一个更详细的图例,但我无法删除初始标签。我打算简单地用一个白色方块将其挡住,但是否有方法只保留我自定义的图例?

gab6jxml

gab6jxml1#

您可以通过设置geom="point"来删除点的标签,这意味着仅使用点进行绘图(默认值为geom = c("point", "text"))。
使用基于iris的最小可重现示例:

library(factoextra)

iris2 <- subset(iris, Species != "setosa")
res.pca <- prcomp(iris2[, -5], scale = TRUE)

pca_biplot <- fviz_pca_biplot(res.pca,
  repel = TRUE, max.overlaps = Inf,
  col.var = "#000000",
  axes = c(3, 4),
  habillage = iris2$Species,
  col.ind = "#696969",
  labels = NULL,
  geom = "point"
)

pca_biplot +
  labs(title = "ACP", x = "CP3 (15,3%)", y = "CP4 (9,6%)") +
  scale_color_manual(values = c("blue", "red")) +
  theme_minimal()

相关问题