[英]Adding group information to 3d plot in FactoMineR
我的代碼這就是我正在運行的
library(FactoMineR); library(factoextra)
res.pca <- PCA(t(data),ncp = 10, graph = FALSE)
res.hcpc <- HCPC(res.pca, graph = FALSE)
fviz_dend(res.hcpc,
cex = 0.7, # Label size
palette = "jco", # Color palette see ?ggpubr::ggpar
rect = TRUE, rect_fill = TRUE, # Add rectangle around groups
rect_border = "jco", # Rectangle color
labels_track_height = 0.8 # Augment the room for labels
)
tiff("plot.tiff",width=3000,height=1856,res=600)
plot(res.hcpc, choice = "3D.map",ind.names=TRUE,cex.axis=3.5,cex.symbols=3.5,xlab="",ylab="")
dev.off()
我得到的是這個
這里有一件事是我不想將集群信息添加到我的圖表中,我寧願根據我的元數據信息來標記它,在我的情況下它是FAB
,它是我的元數據文件中的一列
我希望看到這樣的東西,其中樣本是基於細胞系組進行注釋的。
如何在我的繪圖功能中看不到任何選項來添加相同的
任何建議或幫助將不勝感激
這是一個玩具示例,說明如何繪制 3D 地圖以對主成分 (HCPC) 進行層次聚類。
library(FactoMineR)
iris <- data(iris)
rownames(iris) <- sprintf("A%03d", 1:150)
head(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
A001 5.1 3.5 1.4 0.2 setosa
A002 4.9 3.0 1.4 0.2 setosa
A003 4.7 3.2 1.3 0.2 setosa
A004 4.6 3.1 1.5 0.2 setosa
A005 5.0 3.6 1.4 0.2 setosa
A006 5.4 3.9 1.7 0.4 setosa
res.pca <- PCA(iris[,1:4], graph=FALSE)
hc <- HCPC(res.pca, nb.clust=-1)
plot(hc, choice="3D.map", angle=60)
更新 #1:通過調整 HCPC 調用對象的集群級別,設法更改 plot.HCPC 的 2D 因子圖的標簽
#before changes
plot(hc, choice="map")
levels(hc$call$X$clust) <- c("setosa", "versicolor", "virginica")
plot(hc, choice="map")
注意:我已將行名更改為物種名稱(加上行號)以幫助識別分組。 添加參數ind.names=FALSE
將刪除圖中的單個標簽。 另請注意,圖例中默認存在“集群”一詞。
更新 #2:找到plot.HCPC的源代碼。
請注意,圖例行為在第 54 行和第 55 行定義:
for(i in 1:nb.clust) leg=c(leg, paste("cluster",levs[i]," ", sep=" "))
legend("topleft", leg, text.col=as.numeric(levels(X$clust)),cex=0.8)
這意味着,根據設計,圖例將采用創建的集群數量,並將圖例插入到圖的左上角,如“集群 1”、“集群 2”等。
您可能想要分叉 repo,並重新調整代碼的用途。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.