以簇为颜色的R双图

以簇为颜色的R双图,r,ggplot2,pca,R,Ggplot2,Pca,我在PCA变换后进行聚类,我想在PCA空间的前二维或三维可视化聚类结果,以及原始轴对投影PCA轴的贡献 我使用了使用ggplot的factoextra库,它运行良好,但我想去掉图例: 我的代码: # Load iris dataset data(iris) # PCA pca <- prcomp(iris[,-5], scale=TRUE) df.pca <- pca$x # Cluster over the three first PCA dimensions kc <-

我在PCA变换后进行聚类,我想在PCA空间的前二维或三维可视化聚类结果,以及原始轴对投影PCA轴的贡献

我使用了使用ggplot的
factoextra
库,它运行良好,但我想去掉图例

我的代码:

# Load iris dataset
data(iris)

# PCA
pca <- prcomp(iris[,-5], scale=TRUE)
df.pca <- pca$x

# Cluster over the three first PCA dimensions
kc <- kmeans(df.pca[,1:3], 5)

# 2-D biplot (how to get rid of legend?)
# install.packages("devtools")
# library("devtools")
# install_github("kassambara/factoextra")
library(factoextra)
fviz_pca_biplot(pca, label="var", habillage=as.factor(kc$cluster)) +
  labs(color=NULL) + ggtitle("") +
  theme(text = element_text(size = 15),
      panel.background = element_blank(), 
      panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      axis.line = element_line(colour = "black"),
      legend.key = element_rect(fill = "white"))
#加载iris数据集
数据(iris)
#主成分分析

pca我认为您应该尝试
主题(legend.position=“none”)

这就是我得到的:

这也应该有效: 在
ggtitle(“”)


我无法安装要检查的
factoextra
软件包,但您能否在
ggtitle(“”
)之后添加
+指南(shape=FALSE)
?几乎!我需要摆脱两个传说,而不仅仅是一个。我更新了我的评论作为答案,你能确认它的工作吗?工作完美!我想我已经试过了。谢谢
library(rgl)
text3d(pca$x[,1:3],texts=rep("*",dim(pca$x)[1]), col=kc$cluster) # points
text3d(1*pca$rotation[,1:3], texts=rownames(pca$rotation), col="red") # arrows title
coords <- NULL
for (i in 1:nrow(pca$rotation)) {
  coords <- rbind(coords, rbind(c(0,0,0),1*pca$rotation[i,1:3]))
}
lines3d(coords, col="blue", lwd=1)
 library(factoextra)
 plot(fviz_pca_biplot(pca, label="var", 
  habillage=as.factor(kc$cluster)) + ggtitle("") +
  theme(text = element_text(size = 15), 
      panel.background = element_blank(), 
      panel.grid.major = element_blank(), 
      panel.grid.minor = element_blank(), 
      axis.line = element_line(colour = "black"),
      legend.position="none"))
library(factoextra)
fviz_pca_biplot(pca, label="var", habillage=as.factor(kc$cluster)) +
  labs(color=NULL) + 
  ggtitle("") + guides(shape=FALSE, color=FALSE)
theme(text = element_text(size = 15),
      panel.background = element_blank(), 
      panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      axis.line = element_line(colour = "black"))